0

私のプロジェクトでは、Mfc アプリケーションの上にノンブロッキング QWizard を作成する必要があります。これを行うには、ここの指示に従いました(リンク

QWizardPage 内の QRadioButton をクリックすると、UI が適切に更新されないように見えます。次のスクリーンショットを参照してください。

1-QWizard の最初のステップ。すべてがよさそうだ

QWizard の最初のステップ。 すべてがよさそうだ

2-QRadioButton をクリックしました。「次へ」ボタンが奇妙な状態になっているのを見てください。

QRadioButton をクリックしました。 ほら、

3-2 番目の QRadioButton をクリックしました。両方の QRadioButton が選択されているように見えます。(はい、それらは相互に排他的です!

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();
}
4

2 に答える 2

0

問題は私の Mfc アプリケーションから来ています。タイマーが 100 ミリ秒ごとにタイマー イベントをイベント ループに送信していたため、Qt アプリケーションを適切に更新できませんでした。そこで、Mfc アプリケーションの OnTimer に QCoreApplication::processEvents() を追加しました。

このようにして、QCoreApplication::processEvents が 100 ミリ秒ごとに呼び出され、Qt UI が正しく更新されるようになりました。

于 2013-06-13T13:25:44.533 に答える
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()));
            }
    }
}

コンテキスト メニューにラジオ ボタンを挿入しようとしたときに、同様の問題が発生しました。

スーロン ザイ

于 2013-06-12T13:36:20.983 に答える