我正在从QDialog做3个标签.然后将2个小部件和1个QDialog添加到3个选项卡.
我称QDialog :: accept和QDialog :: reject.但是我希望调用自定义方法,并且在调用它们时应将对话框屏幕重置为列表框选定的屏幕.我的代码如下:
BTSettingsTab::BTSettingsTab(const QFileInfo &fileInfo, QWidget *parent)
: QDialog(parent)
{
...........
.............
QLabel *topLabel = new QLabel(tr("Choose setting :"));
QListWidget *settingsListBox = new QListWidget;
QStringList settings;
/*for (int i = 1; i <= 30; ++i)
applications.append(tr("Application %1").arg(i));
applicationsListBox->insertItems(0, applications);*/
settings.append(tr("newConfiguration:"));
settings.append(tr("Edit Configuration:"));
settings.append(tr("Delete Configuration:"));
settings.append(tr("add current location to turnoff Places:"));
settings.append(tr("temporarily turnoff distance:"));
settings.append(tr("temporarily turn off turnoff places:"));
settings.append(tr("factory reset:"));
settings.append(tr("turn on distance:"));
settings.append(tr("turn on turnoff places:"));
settings.append(tr("exit"));
settingsListBox->insertItems(0,settings);
QDialogButtonBox *buttonBox = new QDialogButtonBox(QDialogButtonBox::Ok
| QDialogButtonBox::Cancel);
connect(buttonBox, &QDialogButtonBox::accepted, this, &QDialog::accept);
connect(buttonBox, &QDialogButtonBox::rejected, this, &QDialog::reject);
QVBoxLayout *layout = new QVBoxLayout;
layout->addWidget(topLabel);
layout->addWidget(settingsListBox);
layout->addWidget(buttonBox);
setLayout(layout);
}
我看到了你的帖子.谢谢.我实现了重载函数,并且断点命中了它们.我得到了所选项目的行号.我使用了QString * curr = settingsListBox-> currentItem()-> text();
现在如何启动新窗口?
解决方法:
方法QDialog :: accept和QDialog :: reject是虚拟的,因此可以在您的自定义对话框中覆盖它们(在您的情况下-BTSettingsTab继承自QDialog).
如果要在接受和拒绝上替换行为-只需在重写的方法中实现所需的行为即可.或者,您可以实现自己的方法BTSettingsTab :: __ OnAccept()和_OnReject()并将按钮连接到它们,而不是将它们连接到QDialog :: accept和拒绝.
如果要将自定义行为添加到默认QDialog的行为中,请在重载版本的末尾分别调用QDialog :: accept()和QDialog :: reject.