wxProgressDialog Flicker

If you are using the main C++ distribution of wxWidgets, Feel free to ask any question related to wxWidgets development here. This means questions regarding to C++ and wxWidgets, not compile problems.
Post Reply
sam_des
Earned a small fee
Earned a small fee
Posts: 12
Joined: Wed Aug 30, 2017 4:55 am

wxProgressDialog Flicker

Post by sam_des » Wed Feb 12, 2020 5:27 am

Hello,

I am trying to use wxProgressDialog, with wxWidgets 3.0.4, and MSVC 2012 & mingw-gcc . Here are 2 lines of code I'm using,

Code: Select all

wxProgressDialog progress( APP_TITLE, _("Reading Records. Please Wait..."), m_MaxFTU, this, wxPD_APP_MODAL|wxPD_AUTO_HIDE|wxPD_SMOOTH );

// code updating 'i' & reading from file

progress.Update( i+1, wxString::Format( _("Reading Records. Please Wait...\nRecords Read - %d of %d"), i+1, m_MaxFTU ) );
With MSVC, it runs too fast, I can't even see ProgressDialog actually progressing. That may be fine but it causes entire app mainwindow to flicker twice, first when dialog is created & second when dialog gets auto-hidden.
But with gcc, no such flicker is seen, OTOH code runs considerably slower & I can see each step of progress, although exact same source is being compiled for both gcc & MSVC.

So how to avoid the flicker ?

TIA,
sam_des

User avatar
doublemax
Moderator
Moderator
Posts: 14630
Joined: Fri Apr 21, 2006 8:03 pm
Location: $FCE2

Re: wxProgressDialog Flicker

Post by doublemax » Wed Feb 12, 2020 6:35 am

If your inner loop is too fast, try updating the progress dialog only sometimes, e.g. 5-10 times per second.

Code: Select all

wxProgressDialog progress( APP_TITLE, _("Reading Records. Please Wait..."), m_MaxFTU, this, wxPD_APP_MODAL|wxPD_AUTO_HIDE|wxPD_SMOOTH );

wxLongLong next_update = 0;
for(...) {

  if( wxGetLocalTimeMillis() > next_update ) {
    progress.Update( i+1, wxString::Format( _("Reading Records. Please Wait...\nRecords Read - %d of %d"), i+1, m_MaxFTU ) );
    next_update = wxGetLocalTimeMillis() + 200;   // 200ms = 5 updates per second
  }
}
Use the source, Luke!

Post Reply