Results 1 to 8 of 8

Thread: flush draw events

  1. #1
    Join Date
    May 2008
    Location
    Melbourne, Australia
    Posts
    136
    Thanks
    9
    Thanked 3 Times in 3 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default flush draw events

    hello,

    In my program the user chooses a file with QFileDialog::getOpenFileName() and then a heavy operation gets performed on that file.
    My problem is that the dialog is still partly visible during the heavy operation.

    What is a good strategy to make sure the dialog is completely hidden before I start the heavy operation? Is there a way to flush all the draw events. Or do I need to wait some milliseconds?

    I'm sure this problem is common but I didn't notice anything useful in the QWidget API or this forum.

    Richard

  2. #2
    Join Date
    Jan 2006
    Posts
    667
    Thanks
    10
    Thanked 80 Times in 74 Posts
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11 Windows

    Default Re: flush draw events

    QFileDialog::getOpenFileName() returns the path to the existing file. The file dialog should be hidden as soon as the path is returned. The operation that you perform on the file should not be the reason for the dialog still being visible.

    Can you post the code here for better understanding of the problem?

  3. #3
    Join Date
    May 2008
    Location
    Melbourne, Australia
    Posts
    136
    Thanks
    9
    Thanked 3 Times in 3 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: flush draw events

    By partially visible I mean the background widget has not refreshed properly so the dialog is still visible. Do you know a way to flush all pending draw events?

    The relevant code:
    Qt Code:
    1. QString file = QFileDialog::getOpenFileName(this, "Select file");
    2. doHeavyEvent(file);
    To copy to clipboard, switch view to plain text mode 

  4. #4
    Join Date
    Aug 2008
    Location
    Ukraine, Krivoy Rog
    Posts
    1,963
    Thanked 370 Times in 336 Posts
    Qt products
    Qt3 Qt4 Qt5
    Platforms
    MacOS X Unix/X11 Windows

    Default Re: flush draw events

    try to add qApp->processEvent(); in doHeavyEvent(file); or move "havy operations" in worker thread. first approach is simpler.
    Qt Assistant -- rocks!
    please, use tags [CODE] & [/CODE].

  5. #5
    Join Date
    May 2008
    Location
    Melbourne, Australia
    Posts
    136
    Thanks
    9
    Thanked 3 Times in 3 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: flush draw events

    thanks spirit. I couldn't easily get a reference to the application variable but fortunately processEvents() is static:
    Qt Code:
    1. QCoreApplication::processEvents();
    To copy to clipboard, switch view to plain text mode 

  6. #6
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,360
    Thanks
    3
    Thanked 5,015 Times in 4,792 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: flush draw events

    The application object is globally available through a "qApp" variable or using QCoreApplication::instance() static call.
    Your biological and technological distinctiveness will be added to our own. Resistance is futile.

    Please ask Qt related questions on the forum and not using private messages or visitor messages.


  7. #7
    Join Date
    May 2008
    Location
    Melbourne, Australia
    Posts
    136
    Thanks
    9
    Thanked 3 Times in 3 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: flush draw events

    oh really, I didn't realize Qt exposed global references. Is there a list available of the global variables in Qt?

  8. #8
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,360
    Thanks
    3
    Thanked 5,015 Times in 4,792 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: flush draw events

    Actually in Qt4 qApp is not a global variable but a macro that expands to QCoreApplication::instance() (or QApplication::instance(), depending which header file you included).
    Your biological and technological distinctiveness will be added to our own. Resistance is futile.

    Please ask Qt related questions on the forum and not using private messages or visitor messages.


Similar Threads

  1. QGraphicsView Mouse Events
    By tomf in forum Qt Programming
    Replies: 5
    Last Post: 29th July 2008, 15:03
  2. Replies: 5
    Last Post: 30th March 2008, 16:53
  3. Replies: 1
    Last Post: 21st August 2007, 16:25
  4. How to suppress user defined events in processEvents()
    By Artschi in forum Qt Programming
    Replies: 5
    Last Post: 5th July 2007, 10:17
  5. QStackerWidget and mouse events
    By high_flyer in forum Qt Programming
    Replies: 3
    Last Post: 25th April 2006, 19:25

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.