return app.exec(); }
4、 编程实现spinbox和slider(QSlider(Qt::Horizontal))之间的交互,界面如下,两种期间的范围全部是0-130。Title为“enter your age”
#include
int main(int argc,char* argv[]) {
QApplication app(argc,argv);//创建app的构造函数 QWidget *pWidget= new QWidget; //new一个Widget
pWidget->setWindowTitle(\设置caption QSpinBox* spinbox = new QSpinBox; //new一个spinbox
QSlider* slider = new QSlider(Qt::Horizontal); //new一个slider spinbox->setRange(0,130); //设置范围,->符号 slider->setRange(0,130);
QObject::connect(spinbox,SIGNAL(valueChanged(int)),slider,SLOT(setValue(int)));
QObject::connect(slider,SIGNAL(valueChanged(int)),spinbox,SLOT(setValue(int)));
//信号和槽,(发送者,信号,接收者,槽).第一个是spinbox发送给slider的 //第二个是slider发送给spinbox的 spinbox->setValue(23);
//QHBoxLayout是布局管理器,即在水平方向上排列窗口部件 QHBoxLayout* layout = new QHBoxLayout; layout->addWidget(spinbox); layout->addWidget(slider);
pWidget->setLayout(layout); pWidget->show(); //窗体显示
return app.exec(); }
5、 如何编译运行qt程序,命令是什么? qmake -project qmake make
6、 如何将UI界面问件转化成代码的.h文件?(假设ui文件名为gogogo.ui。) UIC -o gogogo.h gogogo.ui
7、 请填写空格处的语句,实现声明自己的槽MyWinExit和信号OnExit。
class MyWindow : public Qwidget {
Q_OBJECT public:
MyWindow(QWidget *parent = 0);
signals:
OnExit(); private slots:
MyWinExit();
}
8、 假设我们建立了一个widget的图形用户界面,如图所示:
那么我们main文件应该怎么写,假设ui的名字为gotocelldialog.ui
#include
#include \ int main(int argc, char *argv[]) {
QApplication app(argc, argv); Ui::GotoCellDialog ui;
QDialog *dialog = new QDialog; ui.setupUi(dialog); dialog->show(); return app.exec(); }
9、 假设文件浏览器的界面定义如下:
/********************************************************************************
** Form generated from reading ui file 'dir.ui' **
** Created: Fri Dec 10 11:46:18 2010
** by: Qt User Interface Compiler version 4.5.0 **
** WARNING! All changes made in this file will be lost when recompiling ui file!
********************************************************************************/
#ifndef UI_DIR_H #define UI_DIR_H
#include
QT_BEGIN_NAMESPACE
class Ui_Dialog { public:
QVBoxLayout *verticalLayout; QComboBox *comboBox; QSplitter *splitter_2;
QSplitter *splitter; QTreeView *treeView; QListView *listView; QTableView *tableView;
void setupUi(QDialog *Dialog) {
if (Dialog->objectName().isEmpty())
Dialog->setObjectName(QString::fromUtf8(\ Dialog->resize(901, 372);
verticalLayout = new QVBoxLayout(Dialog);
verticalLayout->setObjectName(QString::fromUtf8(\ comboBox = new QComboBox(Dialog);
comboBox->setObjectName(QString::fromUtf8(\ comboBox->setMaximumSize(QSize(85, 16777215));
verticalLayout->addWidget(comboBox);
splitter_2 = new QSplitter(Dialog);
splitter_2->setObjectName(QString::fromUtf8(\ splitter_2->setOrientation(Qt::Horizontal); splitter = new QSplitter(splitter_2);
splitter->setObjectName(QString::fromUtf8(\ splitter->setOrientation(Qt::Horizontal); treeView = new QTreeView(splitter);
treeView->setObjectName(QString::fromUtf8(\ splitter->addWidget(treeView); listView = new QListView(splitter);
listView->setObjectName(QString::fromUtf8(\ splitter->addWidget(listView); splitter_2->addWidget(splitter);
tableView = new QTableView(splitter_2);
tableView->setObjectName(QString::fromUtf8(\