QT: sort dialog

来源:互联网 发布:学生空间七天网络下载 编辑:程序博客网 时间:2024/06/12 22:51

new a dialog, add some buttons, button is an object which has a name and has a text.

select some buttons, then form/lay out ver or h

new a groupbox, add some objects, then form/lay out grid

Edit/edit widget. signal slot. tab order

 

 

1. Click File|New Form and choose the "Dialog without Buttons" template.

 

2. Create an OK button and drag it to the top right of the form. Change its objectName to "okButton" and set its default property to "true".  

3Create a Cancel button, and drag it below the OK button. Change its objectName to "cancelButton".

4. Create a vertical spacer and drag it below the Cancel button, then create a More button and drag it below the vertical spacer. Change the More button's objectName to "moreButton", set its text property to "&More", and its checkable property to "true".

5. Click the OK button, then Shift+Click the Cancel button, the vertical spacer, and the More button, then click Form|Lay Out Vertically.生成右边的lay out

 

 

6. Create a group box, two labels, two comboboxes, and one horizontal spacer, and put them
anywhere on the form.

7. Right-click the first combobox and choose Edit Items from the context menu to pop up Qt
Designer's combobox editor. Create one item with the text "None".
8. Right-click the second combobox and choose Edit Items. Create an "Ascending" item and a
"Descending" item.

9.Hold down the Ctrl key (Alt on the Mac) and click and drag the Primary Key group box to create a
copy of the group box (and its contents) on top of the original.

10.Click Edit|Edit Signals/Slots to enter Qt Designer's connection mode,To establish a connection between two widgets, click the sender widget  "OK Button" and drag the red arrow line to the receiver widget"group box 2", then release. select toggeled signal and slot setvisible

11.connect the okButton and the form's accept() slot.Drag the red arrow line from the okButton to an empty part of the form, then release.

 

Save the dialog as sortdialog.ui

 

create a sortdialog.h

#ifndef SORTDIALOG_H
#define SORTDIALOG_H
#include <QDialog>
#include "ui_sortdialog.h"
class SortDialog : public QDialog, public Ui::SortDialog
{
Q_OBJECT
public:
SortDialog(QWidget *parent = 0);
void setColumnRange(QChar first, QChar last);
};
#endif

 

create sortdialog.cpp:

 

1 #include <QtGui>
2 #include "sortdialog.h"

3 SortDialog::SortDialog(QWidget *parent)
4 : QDialog(parent)
5 {
6 setupUi(this);


7 secondaryGroupBox->hide();
8 tertiaryGroupBox->hide();//hides the secondary and tertiary parts of the dialog.


9 layout()->setSizeConstraint(QLayout::SetFixedSize);//making the dialog non-resizable by the user.


10 setColumnRange('A', 'Z');
11 }
12 void SortDialog::setColumnRange(QChar first, QChar last)
13 {
14 primaryColumnCombo->clear();
15 secondaryColumnCombo->clear();
16 tertiaryColumnCombo->clear();
17 secondaryColumnCombo->addItem(tr("None"));
18 tertiaryColumnCombo->addItem(tr("None"));
19 primaryColumnCombo->setMinimumSize(
20 secondaryColumnCombo->sizeHint());//sizeHint() function returns a widget's"ideal" size


21 QChar ch = first;
22 while (ch <= last) {
23 primaryColumnCombo->addItem(QString(ch));
24 secondaryColumnCombo->addItem(QString(ch));
25 tertiaryColumnCombo->addItem(QString(ch));
26 ch = ch.unicode() + 1;
27 }
28 }

 

#include <QApplication>
#include "sortdialog.h"
int main(int argc, char *argv[])
{
QApplication app(argc, argv);
SortDialog *dialog = new SortDialog;
dialog->setColumnRange('C', 'F');
dialog->show();
return app.exec();
}

 

原创粉丝点击