Results 1 to 6 of 6

Thread: GraphicsView paintEvent question

  1. #1
    Join Date
    Jan 2008
    Posts
    91
    Thanks
    8

    Default GraphicsView paintEvent question

    Dear All , I have created a CustomLabel class which is based QLabel, then I added this label to QGraphicsView via QGraphicsProxyWidget.
    Qt Code:
    1. CustomLabel *imageItem = new CustomLabel();
    2. imageItem->setSelectionStatus(true);
    3. imageItem->setImagePath("/home/can/workspace/DenemeGraphic/media/home.png");
    4.  
    5. QGraphicsProxyWidget *pCImageProxyWidgetInstance = new QGraphicsProxyWidget(0, Qt::Window);
    6. pCImageProxyWidgetInstance->setWidget(imageItem);
    7. pCImageProxyWidgetInstance->setCacheMode ( QGraphicsItem::NoCache );
    8. pCImageProxyWidgetInstance->setPos(100,100);
    9. scene->addItem(pCImageProxyWidgetInstance);
    To copy to clipboard, switch view to plain text mode 

    In CustomLabel I writed a paintEvent(QPaintEvent *pe) function, the problem is , always it is refreshing , There is a printf() in painEvent and it is continiously printing string.

  2. #2
    Join Date
    Dec 2007
    Posts
    628
    Thanks
    3
    Thanked 89 Times in 87 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    MacOS X Unix/X11 Windows

    Default Re: GraphicsView paintEvent question

    Setting
    pCImageProxyWidgetInstance->setCacheMode ( QGraphicsItem::NoCache );
    Could cause a continues refreshing. Try other cache modes.
    And please show us the paintEvent.

  3. #3
    Join Date
    Jan 2008
    Posts
    91
    Thanks
    8

    Default Re: GraphicsView paintEvent question

    Qt Code:
    1. QPixmap CustomLabel::PreparePixmap()
    2. {
    3. QPixmap pixmap;
    4. pixmap.load(m_ImagePath);
    5. pixmap = pixmap.scaled(WIDTH,HEIGHT,Qt::IgnoreAspectRatio,Qt::FastTransformation);
    6. printf("a\n");
    7. return pixmap;
    8. }
    9. void CustomLabel::paintEvent(QPaintEvent *pe)
    10. {
    11. QPainter painter(this);
    12.  
    13. QPixmap pixmap = PreparePixmap();
    14. setPixmap(pixmap);
    15.  
    16. if(m_Selected)
    17. {
    18.  
    19. QPen pen(Qt::red);
    20. pen.setWidth(5);
    21. painter.setPen(pen);
    22. painter.drawPixmap(3,3,pixmap);
    23. painter.drawRect(0,0,width()-1,height()-1);
    24. }
    25. }
    To copy to clipboard, switch view to plain text mode 


    it is continously printing "a".

  4. #4
    Join Date
    Dec 2007
    Posts
    628
    Thanks
    3
    Thanked 89 Times in 87 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    MacOS X Unix/X11 Windows

    Default Re: GraphicsView paintEvent question

    What printf doing here ?
    Can you please comment the printf statement for a while. use qDebug instead.

  5. #5
    Join Date
    Jan 2008
    Posts
    91
    Thanks
    8

    Default Re: GraphicsView paintEvent question

    I changed it , but it is same, still printing

  6. #6
    Join Date
    Dec 2007
    Posts
    628
    Thanks
    3
    Thanked 89 Times in 87 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    MacOS X Unix/X11 Windows

    Default Re: GraphicsView paintEvent question

    Quote Originally Posted by anafor2004 View Post
    it is continously printing "a".
    Where is it printing ?
    On my machine its running well, a red colored boundary with a pixmap is displaying with no refreshing problem.

Similar Threads

  1. Must QPainter be in paintEvent ??
    By jiapei100 in forum Qt Programming
    Replies: 6
    Last Post: 5th September 2009, 00:09
  2. GraphicsView paintEvent() method implementation problem
    By sujan.dasmahapatra in forum Qt Programming
    Replies: 2
    Last Post: 17th August 2009, 06:54
  3. Possible to use a widget in another widget's paintEvent?
    By robot_love in forum Qt Programming
    Replies: 2
    Last Post: 9th September 2008, 05:18
  4. Question regarding how to paint after zoom.
    By JonathanForQT4 in forum Qt Programming
    Replies: 2
    Last Post: 26th January 2007, 15:34
  5. Replies: 3
    Last Post: 27th November 2006, 09:56

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.