当前位置:网站首页>Qt--- create dialog box 3: implementation of shape variable dialog box

Qt--- create dialog box 3: implementation of shape variable dialog box

2022-06-10 06:30:00 CoderIsArt

occasionally , Different content needs to be displayed to different users , That is, advanced users have advanced model selection display .

such as , Implement the following extended dialog box

1. use QT desinger Create a dialog box and add elements , Here's the picture

Be careful moreButton, Of checkable Property check , as follows ,

 

2. Establish signal slot mechanism , as follows ,

1) add to OK, Cancel The signal slot

 

2) Similar additions moreButton With the display of two combo boxes

Last , The display signal slot is set as follows ,

 3. main.cpp

#include "sortdialog.h"
#include <QApplication>
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 <QDialog>
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;
    }
}

原网站

版权声明
本文为[CoderIsArt]所创,转载请带上原文链接,感谢
https://yzsam.com/2022/161/202206100617202822.html