在我的項目中,我需要在Mfc應用程序的頂部創建一個非阻塞的QWizard。要做到這一點,我遵循這裏的指令(link)QWidget在使用show而不是exec時更新
這樣做有一個奇怪的副作用,它看起來像我的用戶界面沒有正確更新,當我點擊我的QWizardPage內的QRadioButton。請參閱以下屏幕截圖:
1-我的QWizard中的第一步。一切看起來不錯
2,我點擊了一個QRadioButton。看,「下一步」按鈕處於奇怪的狀態。
3-I點擊了第二QRadioButton。看,兩個QRadioButton看起來都被選中了。 (是的,他們是相互排斥的!
4 - 現在,如果我是「鼠標懸停」做一個,在「下一步」按鈕,並在QRadioButton,這迫使更新和我的UI是罰款
我的問題是:使用的,而不是EXEC節目時,如何正確地更新我的UI(我曾嘗試與exec和我的UI正確更新)
我想主線程不更新我的用戶界面,如果我使用show?
謝謝。
編輯
下面是函數的代碼實例化嚮導:
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();
}
應該沒問題。 'show()'就是這個調用,當你不希望窗口是模態的。截圖很不錯,但我想要你的一些代碼... – Zaiborg
@Zaiborg代碼已被添加。我覺得問題可能是主應用程序是Mfc。我用QtCreator做了一個快速測試,你說得對,'show()'不是問題。但就像我在上面的例子中所說的,使用exec解決了這個問題(但是它帶來了一個新問題,我正在使用我的Mfc應用程序) – peterphonic