Results 1 to 5 of 5

Thread: How to run a widget's PaintEvent on another QThread

Threaded View

Previous Post Previous Post   Next Post Next Post
  1. #5
    Join Date
    Jan 2008
    Location
    Alameda, CA, USA
    Posts
    5,321
    Thanks
    316
    Thanked 871 Times in 858 Posts
    Qt products
    Qt5
    Platforms
    Windows

    Default Re: How to run a widget's PaintEvent on another QThread

    If all pictures are preloaded
    You only need to have two pictures loaded at any time - the one you are fading in, and the one you are fading out. In your timeout handler, when the opacity reaches 0 (or 1, whatever), just emit a signal or call a method to load the next image (and swap the pixmaps so that the one that was faded in is now the one to fade out):

    Qt Code:
    1. pixmap1 = pixmap2;
    2. pixmap2.load( nextFileName );
    To copy to clipboard, switch view to plain text mode 

    It is not necessary to have two QPainter instances in the paint event. Just change the opacity on a single QPainter instance between drawing the two pixmaps.

    The only thing you might want to preload is the list of picture file names. And you don't really even need to do that - you can create a QDirIterator as a member of your class, and simply call QDirIterator::next():

    Qt Code:
    1. pixmap1 = pixmap2;
    2. if ( myDirIterator.hasNext() == false )
    3. myDirIterator = QDirIterator( path-to-picture-directory ); // restart from the beginning
    4. pixmap2.load( myDirIterator.next() );
    To copy to clipboard, switch view to plain text mode 

    This code swaps the pixmaps, then checks to see if there are any files remaining in the list. If there are still files remaining, it loads the next one. If not, it resets the iterator back to the beginning and then loads the first one.
    Last edited by d_stranz; 4th April 2015 at 04:30.

Similar Threads

  1. Replies: 1
    Last Post: 9th May 2012, 08:58
  2. Replies: 1
    Last Post: 11th March 2011, 19:34
  3. How to paint a widget outside paintEvent()
    By wesley in forum Qt Programming
    Replies: 10
    Last Post: 27th February 2008, 03:19
  4. painting a widget outside a paintEvent
    By jayw710 in forum Qt Programming
    Replies: 1
    Last Post: 25th June 2007, 23:18
  5. New thread to handle paintEvent
    By bitChanger in forum Qt Programming
    Replies: 1
    Last Post: 9th March 2006, 21:41

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
  •  
Qt is a trademark of The Qt Company.