Results 1 to 3 of 3

Thread: use painter in QGraphicsScene::drawForeground

  1. #1
    Join Date
    Apr 2009
    Location
    Valencia (Spain)
    Posts
    245
    Thanks
    38
    Thanked 19 Times in 19 Posts
    Qt products
    Qt4
    Platforms
    Symbian S60

    Default use painter in QGraphicsScene::drawForeground

    Hi,

    I want to draw a QRectF on my graphicsScene, but I don't know why it doesn't work.

    Qt Code:
    1. void myScene::drawBackground ( QPainter * painter, const QRectF & rect )
    2. {
    3. QRectF rec(m_startRectPoint, getCursorScenePos/*this function works perfectly*/());
    4. painter->setPen(QPen(Qt::black, 1, Qt::DashLine));
    5. painter->drawRect(rec);
    6. update();
    7.  
    8. //QGraphicsScene::drawForeground(painter, rect);
    9. QGraphicsScene::drawBackground(painter, rect);
    10. }
    To copy to clipboard, switch view to plain text mode 

    I want to draw a rectangle which starts in "m_startREctPoint" and finishes in the mouse pointer, at each moment (I did similar things using paint event in the QGraphicsItems).
    Am I doing something wrong there?

    EDIT: I forgot to say something, if you minimize and maximize the widow it paints it well, as expected.

    thanks!

  2. #2
    Join Date
    Aug 2009
    Posts
    17
    Thanked 1 Time in 1 Post
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: use painter in QGraphicsScene::drawForeground

    Hi ..

    I want just ask: How do you force the scene to call your drawBackground() method? It seems that it isn't called when you move the mouse. Have you tryied QGraphicsScene::invalidate()?

    By the way, I have very similar problem with drawForeground() ..
    Please tell me, if you solve this.

  3. #3
    Join Date
    Apr 2009
    Location
    Valencia (Spain)
    Posts
    245
    Thanks
    38
    Thanked 19 Times in 19 Posts
    Qt products
    Qt4
    Platforms
    Symbian S60

    Default Re: use painter in QGraphicsScene::drawForeground

    Yep, now it works here. By the way, I don't force it, it's called at each moment, as far as I know as paint() event.

    I just needed to move the "update()" statment after QGraphicsScene::drawBackground(painter, rect);

Similar Threads

  1. Rendering 3D Objects on Ubuntu
    By Sandip in forum Qt Programming
    Replies: 3
    Last Post: 19th January 2009, 14:29
  2. Problem with Painter in Qt4.4.1
    By merry in forum Qt Programming
    Replies: 1
    Last Post: 1st September 2008, 13:47
  3. Painter greyscale, image quality paint-brush!
    By patrik08 in forum Qt Programming
    Replies: 4
    Last Post: 22nd March 2007, 20:32
  4. How to manage QPainter?
    By Caius Aérobus in forum Qt Programming
    Replies: 3
    Last Post: 28th April 2006, 13:20
  5. Painter not active!
    By Caius Aérobus in forum Qt Programming
    Replies: 7
    Last Post: 30th March 2006, 15:44

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.