Results 1 to 2 of 2

Thread: Changing renderHints of QGraphicsView after object creation

  1. #1
    Join Date
    Feb 2009
    Posts
    79
    Thanks
    11
    Thanked 5 Times in 5 Posts
    Qt products
    Qt4
    Platforms
    Windows

    Default Changing renderHints of QGraphicsView after object creation

    Hi,

    I am new to QT programming (but I really like it :-)) and here is an issue I do not know how to solve:

    I would like to be able to switch the renderHint QPainter::SmotthPixmapTransform on and off dynamically.

    My custom QGraphicsItem looks like

    Qt Code:
    1. class MyItem : public QGraphicsItem
    2. {
    3. public:
    4. MyItem()
    5. {
    6. QGraphicsLineItem * top = new QGraphicsLineItem(...,this);
    7. QGraphicsLineItem * left = new QGraphicsLineItem(...,this);
    8. }
    9. void paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget)
    10. {
    11. if(mouseaction_going_on)
    12. painter->setRenderHint(QPainter::SmoothPixmapTransform, false);
    13. else
    14. painter->setRenderHint(QPainter::SmoothPixmapTransform, true);
    15. }
    16. }
    To copy to clipboard, switch view to plain text mode 
    But in practice, nothing happens, the rendering is performed with exactly those renderHints that have been specified at creation time of the QGraphicsView.

    What about the painter->save() and restore() functions? Might they help me?

    By the way, at whcih stage of the painting procedure is the painting of the child items of MyItem perfomed? Maybe the painting of them is already done when it comes to my setRenderHints()-calls.

    Thank you very much in advance for your great support!!!

    Best Regards,
    Oliver
    Last edited by olidem; 2nd March 2009 at 09:08. Reason: reformatted to look better

  2. #2
    Join Date
    Feb 2009
    Posts
    79
    Thanks
    11
    Thanked 5 Times in 5 Posts
    Qt products
    Qt4
    Platforms
    Windows

    Smile Re: Changing renderHints of QGraphicsView after object creation

    Solution

    Hi,
    I solved the problem on my own. For those of you who are interested:

    instead of trying to configure the painter in my custom item class,
    I just call before my operation
    Qt Code:
    1. MyItem::mousePressEvent(...){
    2. this->scene()->views().first()->setRenderHint(QPainter::SmoothPixmapTransform, false);
    3. }
    To copy to clipboard, switch view to plain text mode 

    and after it

    Qt Code:
    1. MyItem::mouseReleaseEvent(...){
    2. this->scene()->views().first()->setRenderHint(QPainter::SmoothPixmapTransform, true);
    3. }
    To copy to clipboard, switch view to plain text mode 

    And it works!
    Nice!
    I really start liking Qt!
    Regards,
    Olli

Tags for this Thread

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.