私のプロジェクトでは、Mfc アプリケーションの上にノンブロッキング QWizard を作成する必要があります。これを行うには、ここの指示に従いました(リンク)
QWizardPage 内の QRadioButton をクリックすると、UI が適切に更新されないように見えます。次のスクリーンショットを参照してください。
1-QWizard の最初のステップ。すべてがよさそうだ
2-QRadioButton をクリックしました。「次へ」ボタンが奇妙な状態になっているのを見てください。
3-2 番目の QRadioButton をクリックしました。両方の QRadioButton が選択されているように見えます。(はい、それらは相互に排他的です!
4-ここで、「次へ」ボタンと QRadioButton の上に「マウス オーバー」すると、強制的に更新され、UI は問題ありません。
私の質問は: exec の代わりに show を使用するときに UI を適切に更新するにはどうすればよいですか? (私は exec を試しましたが、UI は適切に更新されています)
showを使用すると、メインスレッドがUIを更新していないと思いますか?
ありがとうございました。
編集
ウィザードをインスタンス化する関数のコードは次のとおりです。
void QtMfcFacade::startDevicesConfigurationWizard(HWND hWnd)
{
QWinWidget* win = new QWinWidget( hWnd );
win->showCentered();
DevicesConfigurationWizard *devicesConfigurationWizardUI = new DevicesConfigurationWizard(win);
devicesConfigurationWizardUI->setModal(true);
devicesConfigurationWizardUI->show();
}
以下は私のQWizardクラスです:
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()));
}
}
}
更新を強制しようとする編集は、これまでのところ問題を解決していません
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();
}