Qt : 创建对话框(2)— 创建可扩展对话框
程序员文章站
2022-05-16 11:13:19
...
先上效果图。我们要实现的就是在点击More之后对话框呈现下图的扩展状态,再次点击会收回第一张图片的效果。
==》界面设置部分不过多赘述。请参考下图文及简单说明。
代码如下:
/********************************************************************************
** Form generated from reading UI file 'sortdialog.ui'
**
** Created by: Qt User Interface Compiler version 5.4.2
**
** WARNING! All changes made in this file will be lost when recompiling UI file!
********************************************************************************/
#ifndef UI_SORTDIALOG_H
#define UI_SORTDIALOG_H
#include <QtCore/QVariant>
#include <QtWidgets/QAction>
#include <QtWidgets/QApplication>
#include <QtWidgets/QButtonGroup>
#include <QtWidgets/QComboBox>
#include <QtWidgets/QDialog>
#include <QtWidgets/QGridLayout>
#include <QtWidgets/QGroupBox>
#include <QtWidgets/QHeaderView>
#include <QtWidgets/QLabel>
#include <QtWidgets/QPushButton>
#include <QtWidgets/QSpacerItem>
#include <QtWidgets/QVBoxLayout>
QT_BEGIN_NAMESPACE
class Ui_SortDialog
{
public:
QGridLayout *gridLayout_4;
QGroupBox *primarygroupBox;
QGridLayout *gridLayout;
QLabel *label;
QComboBox *primarycolumncomboBox;
QSpacerItem *horizontalSpacer;
QLabel *label_2;
QComboBox *primaryordercomboBox;
QVBoxLayout *verticalLayout;
QPushButton *okButton;
QPushButton *CancelButton;
QSpacerItem *verticalSpacer;
QPushButton *moreButton;
QGroupBox *secondarygroupBox;
QGridLayout *gridLayout_2;
QLabel *label_3;
QComboBox *secondarycolumncomboBox;
QSpacerItem *horizontalSpacer_2;
QLabel *label_4;
QComboBox *secondaryordercomboBox;
QGroupBox *tertiarygroupBox;
QGridLayout *gridLayout_3;
QLabel *label_5;
QComboBox *tertialycolumncomboBox;
QSpacerItem *horizontalSpacer_3;
QLabel *label_6;
QComboBox *tertiaryordercomboBox;
QSpacerItem *verticalSpacer_2;
void setupUi(QDialog *SortDialog)
{
if (SortDialog->objectName().isEmpty())
SortDialog->setObjectName(QStringLiteral("SortDialog"));
SortDialog->resize(337, 467);
gridLayout_4 = new QGridLayout(SortDialog);
gridLayout_4->setSpacing(6);
gridLayout_4->setContentsMargins(11, 11, 11, 11);
gridLayout_4->setObjectName(QStringLiteral("gridLayout_4"));
primarygroupBox = new QGroupBox(SortDialog);
primarygroupBox->setObjectName(QStringLiteral("primarygroupBox"));
gridLayout = new QGridLayout(primarygroupBox);
gridLayout->setSpacing(6);
gridLayout->setContentsMargins(11, 11, 11, 11);
gridLayout->setObjectName(QStringLiteral("gridLayout"));
label = new QLabel(primarygroupBox);
label->setObjectName(QStringLiteral("label"));
gridLayout->addWidget(label, 0, 0, 1, 1);
primarycolumncomboBox = new QComboBox(primarygroupBox);
primarycolumncomboBox->setObjectName(QStringLiteral("primarycolumncomboBox"));
gridLayout->addWidget(primarycolumncomboBox, 0, 1, 1, 1);
horizontalSpacer = new QSpacerItem(29, 20, QSizePolicy::Expanding, QSizePolicy::Minimum);
gridLayout->addItem(horizontalSpacer, 0, 2, 1, 1);
label_2 = new QLabel(primarygroupBox);
label_2->setObjectName(QStringLiteral("label_2"));
gridLayout->addWidget(label_2, 1, 0, 1, 1);
primaryordercomboBox = new QComboBox(primarygroupBox);
primaryordercomboBox->setObjectName(QStringLiteral("primaryordercomboBox"));
gridLayout->addWidget(primaryordercomboBox, 1, 1, 1, 2);
gridLayout_4->addWidget(primarygroupBox, 0, 0, 1, 1);
verticalLayout = new QVBoxLayout();
verticalLayout->setSpacing(6);
verticalLayout->setObjectName(QStringLiteral("verticalLayout"));
okButton = new QPushButton(SortDialog);
okButton->setObjectName(QStringLiteral("okButton"));
okButton->setEnabled(true);
verticalLayout->addWidget(okButton);
CancelButton = new QPushButton(SortDialog);
CancelButton->setObjectName(QStringLiteral("CancelButton"));
CancelButton->setEnabled(false);
verticalLayout->addWidget(CancelButton);
verticalSpacer = new QSpacerItem(20, 13, QSizePolicy::Minimum, QSizePolicy::Expanding);
verticalLayout->addItem(verticalSpacer);
moreButton = new QPushButton(SortDialog);
moreButton->setObjectName(QStringLiteral("moreButton"));
moreButton->setEnabled(true);
verticalLayout->addWidget(moreButton);
gridLayout_4->addLayout(verticalLayout, 0, 1, 2, 1);
secondarygroupBox = new QGroupBox(SortDialog);
secondarygroupBox->setObjectName(QStringLiteral("secondarygroupBox"));
gridLayout_2 = new QGridLayout(secondarygroupBox);
gridLayout_2->setSpacing(6);
gridLayout_2->setContentsMargins(11, 11, 11, 11);
gridLayout_2->setObjectName(QStringLiteral("gridLayout_2"));
label_3 = new QLabel(secondarygroupBox);
label_3->setObjectName(QStringLiteral("label_3"));
gridLayout_2->addWidget(label_3, 0, 0, 1, 1);
secondarycolumncomboBox = new QComboBox(secondarygroupBox);
secondarycolumncomboBox->setObjectName(QStringLiteral("secondarycolumncomboBox"));
gridLayout_2->addWidget(secondarycolumncomboBox, 0, 1, 1, 1);
horizontalSpacer_2 = new QSpacerItem(54, 20, QSizePolicy::Expanding, QSizePolicy::Minimum);
gridLayout_2->addItem(horizontalSpacer_2, 0, 2, 1, 1);
label_4 = new QLabel(secondarygroupBox);
label_4->setObjectName(QStringLiteral("label_4"));
gridLayout_2->addWidget(label_4, 1, 0, 1, 1);
secondaryordercomboBox = new QComboBox(secondarygroupBox);
secondaryordercomboBox->setObjectName(QStringLiteral("secondaryordercomboBox"));
gridLayout_2->addWidget(secondaryordercomboBox, 1, 1, 1, 2);
gridLayout_4->addWidget(secondarygroupBox, 2, 0, 1, 1);
tertiarygroupBox = new QGroupBox(SortDialog);
tertiarygroupBox->setObjectName(QStringLiteral("tertiarygroupBox"));
gridLayout_3 = new QGridLayout(tertiarygroupBox);
gridLayout_3->setSpacing(6);
gridLayout_3->setContentsMargins(11, 11, 11, 11);
gridLayout_3->setObjectName(QStringLiteral("gridLayout_3"));
label_5 = new QLabel(tertiarygroupBox);
label_5->setObjectName(QStringLiteral("label_5"));
gridLayout_3->addWidget(label_5, 0, 0, 1, 1);
tertialycolumncomboBox = new QComboBox(tertiarygroupBox);
tertialycolumncomboBox->setObjectName(QStringLiteral("tertialycolumncomboBox"));
gridLayout_3->addWidget(tertialycolumncomboBox, 0, 1, 1, 1);
horizontalSpacer_3 = new QSpacerItem(54, 20, QSizePolicy::Expanding, QSizePolicy::Minimum);
gridLayout_3->addItem(horizontalSpacer_3, 0, 2, 1, 1);
label_6 = new QLabel(tertiarygroupBox);
label_6->setObjectName(QStringLiteral("label_6"));
gridLayout_3->addWidget(label_6, 1, 0, 1, 1);
tertiaryordercomboBox = new QComboBox(tertiarygroupBox);
tertiaryordercomboBox->setObjectName(QStringLiteral("tertiaryordercomboBox"));
gridLayout_3->addWidget(tertiaryordercomboBox, 1, 1, 1, 2);
gridLayout_4->addWidget(tertiarygroupBox, 3, 0, 1, 1);
verticalSpacer_2 = new QSpacerItem(20, 9, QSizePolicy::Minimum, QSizePolicy::Expanding);
gridLayout_4->addItem(verticalSpacer_2, 1, 0, 1, 1);
QWidget::setTabOrder(primarycolumncomboBox, primaryordercomboBox);
QWidget::setTabOrder(primaryordercomboBox, secondarycolumncomboBox);
QWidget::setTabOrder(secondarycolumncomboBox, secondaryordercomboBox);
QWidget::setTabOrder(secondaryordercomboBox, tertialycolumncomboBox);
QWidget::setTabOrder(tertialycolumncomboBox, tertiaryordercomboBox);
QWidget::setTabOrder(tertiaryordercomboBox, okButton);
QWidget::setTabOrder(okButton, CancelButton);
QWidget::setTabOrder(CancelButton, moreButton);
retranslateUi(SortDialog);
QObject::connect(okButton, SIGNAL(clicked()), SortDialog, SLOT(accept()));
QObject::connect(CancelButton, SIGNAL(clicked()), SortDialog, SLOT(reject()));
QObject::connect(moreButton, SIGNAL(toggled(bool)), secondarygroupBox, SLOT(setVisible(bool)));
QObject::connect(moreButton, SIGNAL(toggled(bool)), tertiarygroupBox, SLOT(setVisible(bool)));
QMetaObject::connectSlotsByName(SortDialog);
} // setupUi
void retranslateUi(QDialog *SortDialog)
{
SortDialog->setWindowTitle(QApplication::translate("SortDialog", "SortDialog", 0));
primarygroupBox->setTitle(QApplication::translate("SortDialog", "&Primary Key", 0));
label->setText(QApplication::translate("SortDialog", "Coloumn:", 0));
primarycolumncomboBox->clear();
primarycolumncomboBox->insertItems(0, QStringList()
<< QApplication::translate("SortDialog", "none", 0)
);
label_2->setText(QApplication::translate("SortDialog", "Order:", 0));
primaryordercomboBox->clear();
primaryordercomboBox->insertItems(0, QStringList()
<< QApplication::translate("SortDialog", "Ascending", 0)
<< QApplication::translate("SortDialog", "Descending", 0)
);
okButton->setText(QApplication::translate("SortDialog", "OK", 0));
CancelButton->setText(QApplication::translate("SortDialog", "Cancel", 0));
moreButton->setText(QApplication::translate("SortDialog", "&More", 0));
secondarygroupBox->setTitle(QApplication::translate("SortDialog", "&Secondary Key", 0));
label_3->setText(QApplication::translate("SortDialog", "Coloumn:", 0));
secondarycolumncomboBox->clear();
secondarycolumncomboBox->insertItems(0, QStringList()
<< QApplication::translate("SortDialog", "none", 0)
);
label_4->setText(QApplication::translate("SortDialog", "Order:", 0));
secondaryordercomboBox->clear();
secondaryordercomboBox->insertItems(0, QStringList()
<< QApplication::translate("SortDialog", "Ascending", 0)
<< QApplication::translate("SortDialog", "Descending", 0)
);
tertiarygroupBox->setTitle(QApplication::translate("SortDialog", "&Tertiary Key", 0));
label_5->setText(QApplication::translate("SortDialog", "Coloumn:", 0));
tertialycolumncomboBox->clear();
tertialycolumncomboBox->insertItems(0, QStringList()
<< QApplication::translate("SortDialog", "none", 0)
);
label_6->setText(QApplication::translate("SortDialog", "Order:", 0));
tertiaryordercomboBox->clear();
tertiaryordercomboBox->insertItems(0, QStringList()
<< QApplication::translate("SortDialog", "Ascending", 0)
<< QApplication::translate("SortDialog", "Descending", 0)
);
} // retranslateUi
};
namespace Ui {
class SortDialog: public Ui_SortDialog {};
} // namespace Ui
QT_END_NAMESPACE
#endif // UI_SORTDIALOG_H
#ifndef SORTDIALOG_H
#define SORTDIALOG_H
#include <QDialog>
#include"QChar"
namespace Ui {
class SortDialog;
}
class SortDialog : public QDialog
{
Q_OBJECT
public:
explicit SortDialog(QWidget *parent = 0);
~SortDialog();
void setColumnRange(QChar first,QChar last);
private slots:
void on_moreButton_clicked();
private:
Ui::SortDialog *ui;
private:
bool flag;
};
#endif // SORTDIALOG_H
#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');
flag = false;
}
SortDialog::~SortDialog()
{
delete ui;
}
void SortDialog::setColumnRange(QChar first,QChar last)
{
ui->primarycolumncomboBox->clear();
ui->secondarycolumncomboBox->clear();
ui->tertialycolumncomboBox->clear();
ui->secondarycolumncomboBox->addItem(tr("none"));
ui->tertialycolumncomboBox->addItem(tr("none"));
ui->primarycolumncomboBox->setMinimumSize(ui->secondarycolumncomboBox->sizeHint());
QChar ch =first;
while(ch <= last)
{
ui->primarycolumncomboBox->addItem(QString(ch));
ui->secondarycolumncomboBox->addItem(QString(ch));
ui->tertialycolumncomboBox->addItem(QString(ch));
ch = ch.unicode() +1;
}
}
void SortDialog::on_moreButton_clicked()
{
flag = !flag;
if(flag){
ui->secondarygroupBox->show();
ui->tertiarygroupBox->show();
}
else
{
ui->secondarygroupBox->hide();
ui->tertiarygroupBox->hide();
}
}
上一篇: 使用Curl进行抓取远程内容时url中文编码问题示例探讨
下一篇: 公共接口API集合