Results 1 to 20 of 20

Thread: text orientation in qt

Hybrid View

Previous Post Previous Post   Next Post Next Post
  1. #1
    Join Date
    Jan 2008
    Location
    Alameda, CA, USA
    Posts
    5,318
    Thanks
    315
    Thanked 870 Times in 857 Posts
    Qt products
    Qt5
    Platforms
    Windows

    Default Re: text orientation in qt

    Then you need to implement keyPress() and other key-related event handlers on your TextOrientation object so that they add or remove characters to the textObject instance as the user types them. As the textObject is changed, you must call your TextOrientation object's update() method to cause a paint event.

  2. #2
    Join Date
    Apr 2012
    Posts
    12
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11 Windows

    Default Re: text orientation in qt

    i have the code for textbox object to get updated while letters are being typed in a normal state. but once i call the paintevent , it will draw the text contained within the textbox in a specified degree. and it is not at all being included within textbox.it is getting drawn not within the textbox instead in the co-ordinates specified by me. I think i need to have some property of textbox such that once this property is set, the text typed within it will appear in the same degree rotated(ex:as once we set the italic property of font the characters within textbox and also newly typed will get displayed in italic)

  3. #3
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,368
    Thanks
    3
    Thanked 5,017 Times in 4,793 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: text orientation in qt

    Don't draw the whole text at once but instead draw each character one by one under the previous one.
    Your biological and technological distinctiveness will be added to our own. Resistance is futile.

    Please ask Qt related questions on the forum and not using private messages or visitor messages.


  4. #4
    Join Date
    Apr 2012
    Posts
    12
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11 Windows

    Default Re: text orientation in qt

    can you please help me with some code as i am really new to Qt and am trying to crack it.
    I don't understand how to merge the drawn text to the textbox so that it is visible within the textbox.and not in the position specified by me while drawing it

  5. #5
    Join Date
    Jan 2008
    Location
    Alameda, CA, USA
    Posts
    5,318
    Thanks
    315
    Thanked 870 Times in 857 Posts
    Qt products
    Qt5
    Platforms
    Windows

    Default Re: text orientation in qt

    @Deepadev: You have confused me. I think what you are trying to say is that you have a QLineEdit or QTextEdit that the user is typing into, and you want to display the contents of the editor somewhere else (on your TextOrientation widget, I guess). Is that correct? The user is not typing directly into your TextOrientation widget, but into some other editor (QlineEdit or QTextEdit)?

    If that is the case then you should implement a slot in the TextOrientation class that handles the textChanged() signal (from QTextEdit) or textChanged(const QString &) signal (from QLineEdit), whichever one you are using to get the text from the user. In that slot, you simply call update(), which will result in a repaint of the rotated text.

    Qt Code:
    1. // TextOrientation.h:
    2.  
    3. class TextOrientation : public QWidget
    4. {
    5. Q_OBJECT;
    6.  
    7. public:
    8. // usual constructor / destructor stuff
    9.  
    10. protected slots:
    11.  
    12. void onTextChanged( const QString & text ); // assumes "textObject" is a QLineEdit
    13.  
    14. // ...
    15. };
    16.  
    17. // TextOrientation.cpp
    18.  
    19. TextOrientation::TextOrientation( QWidget * parent )
    20. : QWidget( parent )
    21. {
    22. setupUi( this );
    23.  
    24. // ... other constructor stuff as needed
    25.  
    26. connect( textObject, SIGNAL( textChanged( const QString & ) ), this, SLOT( onTextChanged( const QString & ) ) );
    27. }
    28.  
    29. void TextOrientation::onTextChanged( const QString & )
    30. {
    31.  
    32. // Ignore the new text, since TextOrientation::paintEvent() retrieves it from textObject
    33. // and just call update to schedule a repaint
    34. update();
    35. }
    To copy to clipboard, switch view to plain text mode 

  6. #6
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,368
    Thanks
    3
    Thanked 5,017 Times in 4,793 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: text orientation in qt

    I think he doesn't know how to paint the rotated text.
    Your biological and technological distinctiveness will be added to our own. Resistance is futile.

    Please ask Qt related questions on the forum and not using private messages or visitor messages.


  7. #7
    Join Date
    Jan 2008
    Location
    Alameda, CA, USA
    Posts
    5,318
    Thanks
    315
    Thanked 870 Times in 857 Posts
    Qt products
    Qt5
    Platforms
    Windows

    Default Re: text orientation in qt

    I think he doesn't know how to paint the rotated text.
    Could be. It isn't at all clear to me where the problem lies, and as usual there isn't enough source code to figure out what or where.

  8. #8
    Join Date
    Apr 2012
    Posts
    12
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11 Windows

    Default Re: text orientation in qt

    i tried code something like this.
    i am a novice to Qt. so as per my knowledge , i tried something like this.
    header file
    -------------
    Qt Code:
    1. class Dialog : public QDialog
    2. {
    3. Q_OBJECT
    4. int fSize;
    5. int flag1,flag2,flag;
    6.  
    7.  
    8. public:
    9. Dialog(QWidget *parent = 0);
    10. void drawRotatedText(QPainter *painter, float degrees, int x, int y, const QString &text);
    11. QRadioButton *rBtn1,*rBtn2,*rBtn;
    12. QTextEdit *textObject;
    13. void stcpy(char *src,char* dest);
    14. void stcpy1(char *src,char* dest);
    15. void click(QPainter *painter);
    16.  
    17.  
    18. ~Dialog();
    19. protected:
    20. virtual void paintEvent(QPaintEvent *e);
    21.  
    22.  
    23. public slots:
    24. void ischecked1();
    25. void ischecked2();
    26. void ischecked3();
    27.  
    28. };
    To copy to clipboard, switch view to plain text mode 
    source file
    ----------
    Qt Code:
    1. #include "dialog.h"
    2.  
    3. Dialog::Dialog(QWidget *parent) : QDialog(parent)
    4. {
    5. fSize = 72;
    6. /**********flags for preventing crash**************/
    7. flag = 0;
    8. flag1 = 1;
    9. flag2 = 0;
    10. setGeometry(0,0,400,400);
    11. textObject = new QTextEdit(this);
    12. textObject->setGeometry(10,10,300,150);
    13. textObject->setText("deepa");
    14. textObject->setVisible(true);
    15. rBtn =new QRadioButton(this);
    16. rBtn->setVisible(true);
    17. rBtn->setGeometry(10,190,50,30);
    18. rBtn->setChecked(true);
    19. rBtn1 =new QRadioButton(this);
    20. rBtn1->setVisible(true);
    21. rBtn1->setGeometry(90,190,50,30);
    22. rBtn2 =new QRadioButton(this);
    23. rBtn2->setVisible(true);
    24. rBtn2->setGeometry(170,190,50,30);
    25.  
    26. connect(rBtn,SIGNAL(clicked()),this,SLOT(ischecked1()));
    27. connect(rBtn1,SIGNAL(clicked()),this,SLOT(ischecked2()));
    28. connect(rBtn2,SIGNAL(clicked()),this,SLOT(ischecked3()));
    29. this->setAttribute( Qt::WA_TranslucentBackground, true );
    30. }
    31.  
    32. void Dialog::ischecked1()
    33. {
    34. if(flag1 == 0)
    35. {
    36. rBtn->setCheckable(true);
    37. QString str1 = textObject->toPlainText();
    38. QByteArray ba = str1.toLocal8Bit();
    39. char *src = ba.data();
    40. char *dest = (char* )malloc(10) ;
    41. memset(dest,0,10);
    42. stcpy1(src,dest);
    43. QString string = QString::fromLocal8Bit(dest);
    44. textObject->setText(string);
    45. flag1 = 1;
    46. flag2 = 0;
    47. flag = 0;
    48. }
    49.  
    50. }
    51.  
    52.  
    53. /*************This needs to be rotated using paintevent************/
    54. void Dialog::ischecked2()
    55. {
    56. rBtn1->setCheckable(true);
    57. flag = 1;
    58. repaint();
    59. }
    60.  
    61. void Dialog::ischecked3()
    62. {
    63. if (flag2 == 0)
    64. {
    65. rBtn2->setCheckable(true);
    66. QString str1 = textObject->toPlainText();
    67. QByteArray ba = str1.toLocal8Bit();
    68. char *src = ba.data();
    69. //textObject->setFont(QFont("Arial", 10));
    70. char *dest = (char* )malloc(10) ;
    71. memset(dest,0,10);
    72. stcpy(src,dest);
    73. QString string = QString::fromLocal8Bit(dest);
    74. textObject->setText(string);
    75. flag2 = 1;
    76. flag1 = 0;
    77. flag = 0;
    78. }
    79.  
    80. }
    81.  
    82. /***********copying a string with \n to display in vertical order***********/
    83. void Dialog::stcpy(char *src,char* dest)
    84. {
    85. int i,len = 0,j=0;
    86. len=strlen(src);
    87. qDebug()<<"Length ="<<len;
    88. for(i=0;i<len;i++)
    89. {
    90. *(dest+j++) = *(src+i);
    91. *(dest+j++) = '\n';
    92. }
    93. *(dest+j) = '\0';
    94. }
    95.  
    96. /***********copying a string with \n to display in horizontal order***********/
    97. void Dialog::stcpy1(char *src,char* dest)
    98. {
    99. int i,len = 0,j=0;
    100. len=strlen(src);
    101. qDebug()<<"Length ="<<len;
    102. for(i=0;i<len;i=i+2)
    103. {
    104. *(dest+j) = *(src+i);
    105. ++j;
    106. }
    107. *(dest+j) = '\0';
    108. }
    109.  
    110.  
    111. void Dialog::paintEvent(QPaintEvent* e )
    112. {
    113. QPainter painter(this);
    114. painter.setBackgroundMode(Qt::TransparentMode);
    115. painter.setBrush(QColor(255,215,100));
    116. painter.setFont(QFont("Arial", 10));
    117. QRectF rectangle1(0, 180, 350, 40);
    118. painter.drawRect(rectangle1);
    119. painter.drawText(28,199,tr("abc"));
    120. drawRotatedText(&painter, 90,120,196, tr("abc"));
    121. painter.drawLine(195,197,195,195);
    122. painter.drawText(200,200,tr("a"));
    123. painter.drawText(200,210,tr("b"));
    124.  
    125.  
    126.  
    127. /*********functionality of second radiobutton**********/
    128.  
    129. QString str1 = textObject->toPlainText();
    130. QByteArray ba = str1.toLocal8Bit();
    131. char *c_str2 = ba.data();
    132. if(flag == 1)
    133. {
    134. painter.setPen(QColor("red"));
    135. painter.setFont(QFont("Arial", 20));
    136. drawRotatedText(&painter, 90,50,300, tr(c_str2));
    137. flag = 0;
    138. }
    139.  
    140. }
    141.  
    142. /************for drawing rotated text************/
    143.  
    144. void Dialog::drawRotatedText(QPainter *painter, float degrees, int x, int y, const QString &text)
    145. {
    146. painter->save();
    147. painter->translate(x, y);
    148. painter->rotate(degrees);
    149. // painter->scale(70,70);
    150. painter->drawText(0,0, text);
    151. painter->restore();
    152. }
    153.  
    154.  
    155.  
    156.  
    157. Dialog::~Dialog()
    158. {
    159.  
    160. }
    To copy to clipboard, switch view to plain text mode 


    But this is not working properly as i need to change the contents of textedit after this property is set so that the characters typed thereafter should appear in the same rotated format.
    Hope this will make u clear about my problem
    Last edited by wysota; 4th June 2012 at 16:32. Reason: missing [code] tags

  9. #9
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,368
    Thanks
    3
    Thanked 5,017 Times in 4,793 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: text orientation in qt

    What is the problem? Apart the fact you are not using layouts, of course.
    Your biological and technological distinctiveness will be added to our own. Resistance is futile.

    Please ask Qt related questions on the forum and not using private messages or visitor messages.


  10. #10
    Join Date
    Apr 2012
    Posts
    12
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11 Windows

    Default Re: text orientation in qt

    i want the text to appear within the textbox and not in the position specified by me while drawing.
    This is not the proper method of rotating as it won't be applied to the text later typed within textbox.
    I told earlier also, that it should work like property so that once the property is set to 90 degree, the characters typed thereafter within textbox should be typed in 90 dgree angle only. For example: once we set italic property the text later typed appears in italic only within the textbox.

    is there any method to do as such?
    THANKS IN ADVANCE

  11. #11
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,368
    Thanks
    3
    Thanked 5,017 Times in 4,793 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: text orientation in qt

    Quote Originally Posted by DEEPADEV View Post
    I told earlier also, that it should work like property so that once the property is set to 90 degree, the characters typed thereafter within textbox should be typed in 90 dgree angle only. For example: once we set italic property the text later typed appears in italic only within the textbox.
    And the text typed earlier?
    Your biological and technological distinctiveness will be added to our own. Resistance is futile.

    Please ask Qt related questions on the forum and not using private messages or visitor messages.


  12. #12
    Join Date
    Apr 2012
    Posts
    12
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11 Windows

    Exclamation Re: text orientation in qt

    that tooooooo should appear rotated

Similar Threads

  1. Text orientation in header from QStandardItemModel
    By Tondog in forum Qt Programming
    Replies: 3
    Last Post: 2nd October 2012, 08:39
  2. QListWidgetItem's icon and text orientation
    By circass in forum Qt Programming
    Replies: 5
    Last Post: 17th June 2010, 08:03
  3. QTabBar Text and Icon orientation
    By Gravis in forum Qt Programming
    Replies: 0
    Last Post: 16th December 2009, 08:55
  4. QLineEdit text orientation
    By emrares in forum Qt Programming
    Replies: 7
    Last Post: 15th September 2009, 06:25
  5. Vertical Orientation of Text.
    By ashukla in forum Qt Programming
    Replies: 9
    Last Post: 28th January 2008, 12:40

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Qt is a trademark of The Qt Company.