异度部落格

学习是一种生活态度。

0%

QT学习笔记之四 Sort

这几次主要练习 Qt Designer 的设计,所以就做了对话框,没有去做具体的实现,以后有空再写吧….哇哈哈

主要代码如下:

sortdialog.h

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
#ifndef SORTDAILOG_H
#define SORTDAILOG_H
#include <QtGui/QDialog>
#include "ui_sortdailog.h"
namespace Ui
{
class sortdailogClass;
}
class sortdailog : public QDialog
{
Q_OBJECT
public:
sortdailog(QWidget *parent = 0);
~sortdailog();
void setColumnRange(QChar first,QChar last); //用来设置列的范围
private:
Ui::sortdailogClass *ui;
};
#endif // SORTDAILOG_H

sortdialog.cpp

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
#include "sortdailog.h"
#include<QtGui>

sortdailog::sortdailog(QWidget *parent)
: QDialog(parent)
{
ui->setupUi(this);
ui->secondaryGroupBox->hide(); //设置为隐藏
ui->tertiaryGroupBox->hide(); //设置为隐藏
this->layout()->setSizeConstraint(QLayout::SetFixedSize); //将此层设置为适合大小
setColumnRange('A','Z'); //设置默认范围*/
}
sortdailog::~sortdailog()
{
delete ui;
}
void sortdailog::setColumnRange(QChar first,QChar last)
{
//清除原有数据
ui->primaryComboBox->clear();
ui->secondaryComboBox->clear();
ui->tertiaryComboBox->clear();
ui->secondaryComboBox->addItem(tr("None"));
ui->tertiaryComboBox->addItem(tr("None"));
ui->primaryComboBox->setMinimumSize(ui->secondaryComboBox->sizeHint()); //设置理想大小
QChar ch=first;
while(ch<=last)
{
ui->primaryComboBox->addItem(QString(ch)); //QString(ch)因为tr()只能接受字符串类型
ui->secondaryComboBox->addItem(QString(ch));
ui->tertiaryComboBox->addItem(QString(ch));
ch=ch.unicode()+1;
}
}

main.cpp

1
2
3
4
5
6
7
8
9
10
#include <QtGui/QApplication>
#include "sortdailog.h"
int main(int argc, char *argv[])
{
QApplication a(argc, argv);
sortdailog *dialog=new sortdailog;
dialog->setColumnRange('C','H');
dialog->show();
return a.exec();
}