Results 1 to 3 of 3

Thread: How to optimize the drawing process in paintEvent ?

  1. #1
    Join Date
    Jan 2006
    Posts
    162
    Thanks
    9
    Qt products
    Qt3
    Platforms
    Windows

    Default How to optimize the drawing process in paintEvent ?

    Hello everybody,

    As it is expressed in the thread title, I would like to know how to optimize the drawing process of a pixmap in the paintEvent function.

    Let me give you some more explanations about my application. I have an interface between my application and a radio system so I am able to get the current radio frequency. I want to display the radio frequency in my application and I use ten pixmaps (one for each digits) which have some transparency. When a frequency scan is started, the digits are changed according to the real radio frequency and it flicks and I don't know how to do to eliminate it.

    The widget which process the displaying of the digits is constructed with the following style :
    Qt Code:
    1. Qt::WStyle_Customize|Qt::WStyle_NoBorder|Qt::WNoAutoErase
    To copy to clipboard, switch view to plain text mode 

    and here are the two functions I use to display the digit pixmaps :
    Qt Code:
    1. void CMyClass::displayImage(const QPixmap& pix)
    2. {
    3. if( transparency )
    4. {
    5. if ( pix.mask() )
    6. this->setMask( *pix.mask() );
    7. }
    8. // We can use the following code if we are sure that the source and destination graphic devices have the same depth
    9. //QRect rect(event->rect());
    10. //bitBlt(this, rect.topLeft(), &pixmap);
    11.  
    12. // We must use the following code if we are sure that the source and destination graphic devices have a different depth
    13. QPainter painter(this);
    14. painter.drawPixmap(0, 0, pix);
    15. }
    16.  
    17. void CMyClass::paintEvent(QPaintEvent* event)
    18. {
    19. if( this->isShown )
    20. {
    21. if( loadingMode == CMyClass::Static )
    22. {
    23. QPixmap pixmap(images[imageCurrentIndex]);
    24.  
    25. displayImage(pixmap);
    26. }
    27. else if( loadingMode == CMyClass::Dynamic )
    28. {
    29. QPixmap pixmap(files[imageCurrentIndex]);
    30.  
    31. displayImage(pixmap);
    32. }
    33. }
    34. }
    To copy to clipboard, switch view to plain text mode 

    So if someone could tell me how to optimize my diplaying process, it would be great.

    Thanks in advance.

  2. #2
    Join Date
    Feb 2006
    Location
    Oslo, Norway
    Posts
    6,264
    Thanks
    36
    Thanked 1,519 Times in 1,389 Posts
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11 Windows Symbian S60 Maemo/MeeGo

    Default Re: How to optimize the drawing process in paintEvent ?

    It could help a bit if you wouldn't construct a new pixmap in every paint event.
    Thanks to implicit sharing though, the pixmaps share same data in CMyClass::Static mode.
    The bigger problem might be in CMyClass:ynamic mode. As if I understand correctly, it constructs a pixmap from a file in every paint event? That might cause some flickering..

    Edit: How about if you would try to avoid reading pixmaps from files during the paint event?
    In the "dynamic" mode you could draw the pixmaps from the images-array as well. You could make use of some timer or so and read the image files to the image-array once in a while to make it look like it loads the images on the fly. But don't read the pixmaps from files in the paint event.
    Last edited by jpn; 26th April 2006 at 10:40.
    J-P Nurmi

  3. #3
    Join Date
    Jan 2006
    Posts
    162
    Thanks
    9
    Qt products
    Qt3
    Platforms
    Windows

    Default Re: How to optimize the drawing process in paintEvent ?

    Ok, that's true, it is not usefull to construct a Qpixmap object each time so I will correct this as soon as possible.

    Thanks.

Similar Threads

  1. Problems with drawing image in paintEvent of QTreeView
    By Tito Serenti in forum Qt Programming
    Replies: 7
    Last Post: 24th December 2008, 23:25
  2. Problems with QString
    By cyberboy in forum Qt Programming
    Replies: 2
    Last Post: 13th October 2008, 08:18

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.