Results 1 to 5 of 5

Thread: Refresh + QGraphicItem + drawText

  1. #1
    Join Date
    Apr 2008
    Posts
    196
    Thanked 8 Times in 6 Posts
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11 Windows
    Wiki edits
    1

    Default Refresh + QGraphicItem + drawText

    Hey @all,

    for my Project I decided to subclass QGraphicItem and reimplement the paint function.
    Qt Code:
    1. void MyItem::paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget) {
    2. // Draw the pixmap
    3. //painter->drawPixmap(...);
    4.  
    5. // Draw the item text
    6. painter->drawText(QRectF(-_pixmap.width(), 5, _pixmap.width(), 25), Qt::AlignHCenter, "Demotext");
    7. }
    To copy to clipboard, switch view to plain text mode 

    From now, when i move the drawn item, the text aren't repainted / updated. When i move the graphics item fast over the graphics scene, then there are only black fragments from the text, but no "Demotext".

    What I'm doing wrong?

    Best Regards
    NoRulez

  2. #2
    Join Date
    Sep 2008
    Location
    Bangalore
    Posts
    659
    Thanks
    116
    Thanked 42 Times in 41 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: Refresh + QGraphicItem + drawText

    i think the update() is calling before the paint() completes drawText() ..
    use qApp->processEvents(); in the paint() ..
    this paint i think we cant use QThreads() any way u try any other option like mandelbolt example ... http://doc.trolltech.com/4.3/threads-mandelbrot.html
    "Behind every great fortune lies a crime" - Balzac

  3. #3
    Join Date
    Apr 2008
    Posts
    196
    Thanked 8 Times in 6 Posts
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11 Windows
    Wiki edits
    1

    Default Re: Refresh + QGraphicItem + drawText

    I tried also
    Qt Code:
    1. QApplication::processEvents();
    To copy to clipboard, switch view to plain text mode 
    at the end of the function, but nothing was changed.

    I've attached an example to show how it looks

    Best Regards
    NoRulez
    Attached Images Attached Images

  4. #4
    Join Date
    Sep 2008
    Location
    Bangalore
    Posts
    659
    Thanks
    116
    Thanked 42 Times in 41 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: Refresh + QGraphicItem + drawText

    exactly the next update() is called the paint::update() before drawText() ...

    is it possible to port a new QEventLoop() in the code .. ? or QThread() .. this seperate event loop should emit the signal to update() when user moves the cursor ..
    did u see the mandelbrot example ..
    "Behind every great fortune lies a crime" - Balzac

  5. #5
    Join Date
    Apr 2008
    Posts
    196
    Thanked 8 Times in 6 Posts
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11 Windows
    Wiki edits
    1

    Default Re: Refresh + QGraphicItem + drawText

    I think i found the solution, the problem was within the boundingRect() function, where the text wasn't included.

    Best Regards

Similar Threads

  1. Refresh QDataTable
    By shamik in forum Qt Programming
    Replies: 25
    Last Post: 1st December 2006, 05:04

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.