2013-06-12 23 views
0

在我的項目中,我需要在Mfc應用程序的頂部創建一個非阻塞的QWizard。要做到這一點,我遵循這裏的指令(linkQWidget在使用show而不是exec時更新

這樣做有一個奇怪的副作用,它看起來像我的用戶界面沒有正確更新,當我點擊我的QWizardPage內的QRadioButton。請參閱以下屏幕截圖:

1-我的QWizard中的第一步。一切看起來不錯

First step in my QWizard. Everything looks good

2,我點擊了一個QRadioButton。看,「下一步」按鈕處於奇怪的狀態。

I clicked on a QRadioButton. See, the "Next" button is in a weird state.

3-I點擊了第二QRadioButton。看,兩個QRadioButton看起來都被選中了。 (是的,他們是相互排斥的!

I clicked on the second QRadioButton. See, both QRadioButton look selected. (Yes, they are mutually exclusive!)

4 - 現在,如果我是「鼠標懸停」做一個,在「下一步」按鈕,並在QRadioButton,這迫使更新和我的UI是罰款

Now, if I am doing a "mouse over", over the "Next" button and over QRadioButton, that forces an update and my UI is fine

我的問題是:使用的,而不是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(); 
} 
+0

應該沒問題。 'show()'就是這個調用,當你不希望窗口是模態的。截圖很不錯,但我想要你的一些代碼... – Zaiborg

+0

@Zaiborg代碼已被添加。我覺得問題可能是主應用程序是Mfc。我用QtCreator做了一個快速測試,你說得對,'show()'不是問題。但就像我在上面的例子中所說的,使用exec解決了這個問題(但是它帶來了一個新問題,我正在使用我的Mfc應用程序) – peterphonic

回答

0

問題來自我的Mfc應用程序。計時器每100毫秒發送一個計時器事件給事件循環,所以,我的Qt應用程序無法正確更新。所以,我做了什麼,我在Mfc應用程序中將QCoreApplication :: processEvents()添加到OnTimer中。

這樣,QCoreApplication :: processEvents正在通話每100個milisedonds和我的Qt用戶界面現在可以正確地更新。

0

也許這將幫助:

void DevicesConfigurationWizard::setupSingleUserPage() 
{ 
    this->button(this->NextButton)->setEnabled(false); 
    int newPositionY = 0; 
     QVBoxLayout* layout = ui.wpSINGLE_USER->findChild<QVBoxLayout*>("verticalLayout"); 
     QButtonGroup* group = new QButtonGroup(this); // add this 
     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); 
       group->addButton(radioButton); // and add this 
       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())); 
      } 
    } 
} 

得到了類似的問題,當我試圖插入單選按鈕的上下文菜單。

soo long zai

+0

不幸的是,這並沒有解決問題。此外,問題不僅在於QRadioButton,而且在於QPushButton(「下一步」按鈕未更新)。 Thx的幫助 – peterphonic

+0

使用'QWidget :: update()'顯式調用?可能不是最性感的方式,但你可以嘗試在單選按鈕被點擊時適合它... – Zaiborg

+0

都不:(看我更新的帖子,我嘗試了所有可能的方法來強制更新。我真的不明白:/ – peterphonic

相關問題