In my project, I need to create a non-blocking QWizard on the top of my Mfc application. To do this, I followed the instruction here (link)
Doing this have a strange side-effect, it looks like that my UI is not updating properly when I am clicking my QRadioButton inside my QWizardPage. See following screenshots :
1-First step in my QWizard. Everything looks good
2-I clicked on a QRadioButton. See, the "Next" button is in a weird state.
3-I clicked on the second QRadioButton. See, both QRadioButton look selected. (Yes, they are mutually exclusive!
4-Now, if I am doing a "mouse over", over the "Next" button and over QRadioButton, this forces an update and my UI is fine
My question is : How to update properly my UI when using show instead of exec? (I did try with exec and my UI is updating properly)
I guess that main thread is not updating my UI if I use show?
Thank you.
EDIT
Here is the code of the function that instantiate the wizard :
void QtMfcFacade::startDevicesConfigurationWizard(HWND hWnd)
{
QWinWidget* win = new QWinWidget( hWnd );
win->showCentered();
DevicesConfigurationWizard *devicesConfigurationWizardUI = new DevicesConfigurationWizard(win);
devicesConfigurationWizardUI->setModal(true);
devicesConfigurationWizardUI->show();
}
THe following is my QWizard class :
DevicesConfigurationWizard::DevicesConfigurationWizard(QWidget *parent, Qt::WFlags flags)
: QWizard(parent, flags),
{
ui.setupUi(this);
this->setWindowFlags( ( (this->windowFlags() | Qt::CustomizeWindowHint)
& ~Qt::WindowCloseButtonHint & ~Qt::WindowContextHelpButtonHint) );
this->setAttribute( Qt::WA_DeleteOnClose, true );
connect(this, SIGNAL(currentIdChanged(int)), this, SLOT(onClick(int)));
}
void DevicesConfigurationWizard::onClick(int pageId)
{
if (m_currentPageId < pageId)
{
//user clicked next button.
switch (pageId)
{
case PAGE_NUMBER_SINGLE_USER:
{
setupSingleUserPage();
break;
}
default :
{
//problem!!!
}
}
m_currentPageId = pageId;
}
}
void DevicesConfigurationWizard::onRadioButtonClick()
{
this->button(this->NextButton)->setEnabled(true);
this->button(this->FinishButton)->setEnabled(true);
}
void DevicesConfigurationWizard::setupSingleUserPage()
{
this->button(this->NextButton)->setEnabled(false);
int newPositionY = 0;
QVBoxLayout* layout = ui.wpSINGLE_USER->findChild<QVBoxLayout*>("verticalLayout");
for (vector<Events::VCS::PnPDevice>::const_iterator it=m_devices.begin(); it!=m_devices.end(); it++)
{
if (it->type == Events::VCS::HEADSET)
{
//add a radio button
stringstream text;
text << (it->name) << " " << (it->serialNumber) ;
QRadioButton* radioButton = new QRadioButton(this->ui.wpSINGLE_USER);
radioButton->setGeometry(X, Y + newPositionY, WIDHT, HEIGHT);
radioButton->setText(text.str().c_str());
radioButton->setIconSize(QSize(HEIGHT,HEIGHT));
newPositionY = newPositionY + HEIGHT;
layout->insertWidget(0, radioButton);
connect(radioButton, SIGNAL(clicked()), this, SLOT(onRadioButtonClick()));
}
}
}
EDIT trying to force update does not resolved problem so far
void DevicesConfigurationWizard::onRadioButtonClick()
{
this->button(this->NextButton)->setEnabled(true);
this->button(this->FinishButton)->setEnabled(true);
QWidget::update();
this->update();
this->button(this->NextButton)->update();
QList<QRadioButton*> listButton = ui.wpSINGLE_USER->findChildren<QRadioButton*>();
listButton[0]->update();
listButton[1]->update();
QApplication::processEvents();
}
The problem is comming from my Mfc application. A timer was sending a timer event to the event loop every 100 miliseconds, so, my Qt application was not able to update properly. So, what I did, I added QCoreApplication::processEvents() into OnTimer, on Mfc application.
This way, QCoreApplication::processEvents is being call every 100 milisedonds and my Qt UI is now correctly updated.