Results 1 to 4 of 4

Thread: Writing Text on a Rectangle!!!

  1. #1
    Join Date
    Feb 2006
    Location
    New Delhi,India
    Posts
    226
    Thanks
    14
    Thanked 4 Times in 4 Posts
    Qt products
    Qt4
    Platforms
    Windows

    Default Writing Text on a Rectangle!!!

    Hi..

    i would like to write text inside a rectangle created using Q3CanvasRectangle, like some name of it and the coordinates for it.. how do i do that...
    Plz help me in this..

    Thanking you a lot...

    with regards,
    Kapil
    All you have to decide is what to do with the time that is given to you

  2. #2
    Join Date
    Jan 2006
    Posts
    667
    Thanks
    10
    Thanked 80 Times in 74 Posts
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11 Windows

    Default Re: Writing Text on a Rectangle!!!

    I think you can reimplement drawShape and write your text.

  3. #3
    Join Date
    Feb 2006
    Location
    New Delhi,India
    Posts
    226
    Thanks
    14
    Thanked 4 Times in 4 Posts
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: Writing Text on a Rectangle!!!

    Quote Originally Posted by munna
    I think you can reimplement drawShape and write your text.
    thanks for the reply..

    what i have done is used the Q3CanvasText and written by specifying the position.. just the only problem which i am facing is that when i provide motion to the canvas or move it the text does not move...
    so i have to like set on the move for the text also with it..
    what i want is that when i move the rectangle, the text moves with it as if its painted on the rectangle only...

    how to do it..

    thanks,

    with regards,
    Kapil
    All you have to decide is what to do with the time that is given to you

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

    Default Re: Writing Text on a Rectangle!!!

    You have already been given your answer -- subclass QCanvasRectangle and reimplement drawShape so that it paints your text in the rectangle:

    Qt Code:
    1. void CanvasRectangleWithText::drawShape(QPainter &p){
    2. QCanvasRectangle::drawShape(p); // this draws the rectangle
    3. p.drawText(rect(), Qt::AlignCenter, "Some text");
    4. }
    To copy to clipboard, switch view to plain text mode 

Similar Threads

  1. Unhandled exception in qatomic
    By NewGuy in forum Qt Programming
    Replies: 14
    Last Post: 23rd July 2013, 09:49
  2. Match the text beetween two string
    By dreamer in forum Qt Programming
    Replies: 4
    Last Post: 20th May 2008, 14:48
  3. Html text bounding rectangle
    By bunjee in forum Qt Programming
    Replies: 8
    Last Post: 15th May 2008, 11:25
  4. problem in writing text with QFile
    By wei243 in forum Qt Programming
    Replies: 5
    Last Post: 6th March 2007, 14:26
  5. Editable text in QGraphicsView
    By wysota in forum Qt Programming
    Replies: 8
    Last Post: 24th February 2007, 15:30

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.