有时候,需要对不同用户显示不同的内容,也就是高级用户有高级选型显示。
比如,实现如下扩展对话框
1. 用QT desinger创建对话框且添加各元素,如下图
注意moreButton, 的checkable属性勾选,如下,
2. 建立信号槽机制,如下,
1)添加OK, Cancel的信号槽
2)类似的添加moreButton与两个组合框的显示
最后,显示信号槽设置如下,
3. main.cpp
#include "sortdialog.h"
#include
int main(int argc, char *argv[])
{
QApplication a(argc, argv);
SortDialog *sortDlg = new SortDialog;
sortDlg->setColumnRange('C','F');
sortDlg->show();
return a.exec();
}
4. sortdialog.h
#ifndef SORTDIALOG_H
#define SORTDIALOG_H
#include
namespace Ui {
class SortDialog;
}
class SortDialog : public QDialog
{
Q_OBJECT
public:
explicit SortDialog(QWidget *parent = nullptr);
~SortDialog();
void setColumnRange(QChar first, QChar last);
private:
Ui::SortDialog *ui;
};
#endif // SORTDIALOG_H
5. sortdialog.cpp
#include "sortdialog.h"
#include "ui_sortdialog.h"
SortDialog::SortDialog(QWidget *parent) :
QDialog(parent),
ui(new Ui::SortDialog)
{
ui->setupUi(this);
ui->secondaryGroupBox->hide();
ui->tertiaryGroupBox->hide();
layout()->setSizeConstraint(QLayout::SetFixedSize);
setColumnRange('A', 'Z');
}
SortDialog::~SortDialog()
{
delete ui;
}
void SortDialog::setColumnRange(QChar first, QChar last)
{
ui->primaryColumnCombo->clear();
ui->secondaryColumnCombo->clear();
ui->tertiaryColumnCombo->clear();
ui->secondaryColumnCombo->addItem(tr("None"));
ui->tertiaryColumnCombo->addItem(tr("None"));
ui->primaryColumnCombo->setMinimumSize(
ui->secondaryColumnCombo->sizeHint());
QChar ch = first;
while(ch <= last) {
ui->primaryColumnCombo->addItem(QString(ch));
ui->secondaryColumnCombo->addItem(QString(ch));
ui->tertiaryColumnCombo->addItem(QString(ch));
ch = ch.unicode() + 1;
}
}
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)