Results 1 to 10 of 10

Thread: how can i rotate a text ?

  1. #1
    Join Date
    May 2010
    Posts
    100
    Thanks
    1
    Qt products
    Qt3 Qt4 Qt/Embedded
    Platforms
    Unix/X11

    Default how can i rotate a text ?

    Hi,all

    I am haveing a push button on which i want to print a text which is a 90* rotated.

    i have tried using the QPainterPath and QPainter class as below.

    QFont Times("times","30");
    QPainter *painter;
    QMatrix mat;
    QPainterPath path,newpath,textpath;

    textpath.addText(30,70,Times,tr('rotated TEXT"));
    mat.rotate(90);
    newpath.addPath(mat.map(textpath));
    painter->drwaPath(newpath);


    but its giving me 2 error:
    (1)QPainter:Widget ,painting can only begin as a result og paint event;
    (2)QPOinter ainter is not active


    I have read the earlier problem like this ,but i am not able to find out the partilcular souluition.
    please help.thanks to all.

  2. #2
    Join Date
    May 2010
    Posts
    100
    Thanks
    1
    Qt products
    Qt3 Qt4 Qt/Embedded
    Platforms
    Unix/X11

    Default Re: how can i rotate a text ?

    hellow,

    No boy knows?please reply any one,i got stucked with my work.i am a newbie ,i dont know much about this.

    i got success entering into the QPaintEvent() fucntion ,but its giving me errors like:

    Painter is not active.
    painter save/restore unbalanced .

    Plese help.

  3. #3
    Join Date
    Oct 2006
    Location
    New Delhi, India
    Posts
    2,467
    Thanks
    8
    Thanked 334 Times in 317 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: how can i rotate a text ?

    u havent assigned *painter to anything.
    Whats ur latest code ?

    You just need to override the paintEvent of the label.
    and you need to rotate the painter...not path..

  4. #4
    Join Date
    May 2010
    Posts
    100
    Thanks
    1
    Qt products
    Qt3 Qt4 Qt/Embedded
    Platforms
    Unix/X11

    Default Re: how can i rotate a text ?

    yah thanks.

    I have tried this but still i am getting an error :

    this time only one aint event can only begin as a result of painting.
    The problem is that it is not entering into the PaintEvent(QPaintEvent *) function.
    i have given simple qDebug("printf"); its not showing me this printf. i dont know how can i
    do this.

    can any one have little code which can rotate a simple text with the QPainter.It will be
    better if i got as a function.

    Thanks in advance.

  5. #5
    Join Date
    Jan 2006
    Location
    Munich, Germany
    Posts
    4,710
    Thanks
    21
    Thanked 418 Times in 411 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows

    Default Re: how can i rotate a text ?

    the method name is wrong, it should be paintEvent() not PaintEvent().
    ==========================signature=============== ==================
    S.O.L.I.D principles (use them!):
    https://en.wikipedia.org/wiki/SOLID_...iented_design)

    Do you write clean code? - if you are TDD'ing then maybe, if not, your not writing clean code.

  6. #6
    Join Date
    May 2010
    Posts
    100
    Thanks
    1
    Qt products
    Qt3 Qt4 Qt/Embedded
    Platforms
    Unix/X11

    Default Re: how can i rotate a text ?

    yah, its paintEvent not PaintEvent.

    i have written the code like this.

    Widget:aintEvent(QPaintEvent *)
    {

    qDebug("enterd into the paintEvent");

    QFont Times("times","30");
    QPainter *painter;
    QMatrix mat;
    QPainterPath newpath,textpath;

    textpath.addText(30,70,Times,tr('rotated TEXT"));
    mat.rotate(90);
    newpath.addPath(mat.map(textpath));
    painter->drawPath(newpath);

    }

    My main class is the Widget and is derived from QWidget.

    now can any one tell me how can i enter into the above function? please...
    i just want to rotate text,but i dont know how and when it enters into the function shown above.

    there is no error.
    when i compile my application,it gives some messages as below:
    QPainter::begin:Widget painting can only be started as result of paint event.
    what is this?and what is the solution ?


    Thanking you.

  7. #7
    Join Date
    Jan 2006
    Location
    Munich, Germany
    Posts
    4,710
    Thanks
    21
    Thanked 418 Times in 411 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows

    Default Re: how can i rotate a text ?

    paintEvent() is an event handler.
    You are not supposed to call it your self, Qt calls it when it has to be called.
    Just showing the widget will run the paintEvent() code.
    And you forgot to initialize your painter.
    It is also better to allocate the QPainter on the stack so:
    Qt Code:
    1. QPainter painter(this);
    To copy to clipboard, switch view to plain text mode 

    This way, begin() is implicitly called, and the painter object gets destroyed at the end of the function.
    And you don't need to use the matrix, QPainter can rotate for you.
    Have a look at the QPainter docs.
    ==========================signature=============== ==================
    S.O.L.I.D principles (use them!):
    https://en.wikipedia.org/wiki/SOLID_...iented_design)

    Do you write clean code? - if you are TDD'ing then maybe, if not, your not writing clean code.

  8. #8
    Join Date
    May 2010
    Posts
    100
    Thanks
    1
    Qt products
    Qt3 Qt4 Qt/Embedded
    Platforms
    Unix/X11

    Default Re: how can i rotate a text ?

    thanks,this has removed my error:

    But still its not displaying any thing like roated text or roiginal text into my screen.

    can u please specify me what should i (what code ,any thing little code which can display a text) i write into
    the Main function? or into the parent class function.My qDebug inside a paintEvent is allso not gets printed.

    i mean to ask ,what should i do now to display the rotated text,what ever i have done is not showing me any thing.
    can u give me some little code,so that i can run it and understand how does the event gets handled in qt

    Thank you veru much.

  9. #9
    Join Date
    Jan 2006
    Location
    Munich, Germany
    Posts
    4,710
    Thanks
    21
    Thanked 418 Times in 411 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows

    Default Re: how can i rotate a text ?

    As it was said before me:
    You have to Subclass Qlabel and re-implement the QLabel:aintEvent().

    That is all.

    If you have a QLabel that you can see when you run the application, reimplementing its paintEvent() should work too.

    You might want to have a look at the libqext, they implemented such a QLabel which you can use.
    ==========================signature=============== ==================
    S.O.L.I.D principles (use them!):
    https://en.wikipedia.org/wiki/SOLID_...iented_design)

    Do you write clean code? - if you are TDD'ing then maybe, if not, your not writing clean code.

  10. #10
    Join Date
    May 2010
    Posts
    100
    Thanks
    1
    Qt products
    Qt3 Qt4 Qt/Embedded
    Platforms
    Unix/X11

    Default Re: how can i rotate a text ?

    thank you all,

    its working.

    I have build my own class from Q Widget and write a constructor which takes argument as a QPainterPath and QWidget.
    i have also set the rotation angle to 90* into that.

    When something changes into the screen it gets entered into the :aintEvent. And i am rotating the received object to the rotation-angle defined above.

Similar Threads

  1. Rotate a QRectF
    By whitefurrows in forum Qt Programming
    Replies: 5
    Last Post: 15th July 2009, 15:33
  2. Replies: 1
    Last Post: 3rd September 2008, 14:16
  3. To rotate widget
    By ajit in forum Qt Programming
    Replies: 2
    Last Post: 26th September 2007, 10:03
  4. QPolygon rotate
    By xgoan in forum Qt Programming
    Replies: 3
    Last Post: 8th May 2007, 11:18
  5. Rotate QGraphicsPixmapItem
    By durbrak in forum Qt Programming
    Replies: 7
    Last Post: 15th April 2007, 14:51

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
  •  
Digia, Qt and their respective logos are trademarks of Digia Plc in Finland and/or other countries worldwide.