日志
1.3 窗口部件的布局
2015-11-26 18:33
#include <QApplication>
#include <QHBoxLayout> #include <QSlider> #include <QSpinBox> int main(int argc, char** argv) { QApplication app(argc, argv); QWidget *pWindow = new QWidget; pWindow->setWindowTitle(QObject::tr("Enter Your Age")); QSpinBox *pSpinBox = new QSpinBox; //设置spinBox控件的取值范围 pSpinBox->setRange(0, 130); QSlider *pSlider = new QSlider(Qt::Horizontal); pSlider->setRange(0, 130); QObject::connect(pSpinBox, SIGNAL(valueChanged(int)), pSlider, SLOT(setValue(int))); QObject::connect(pSlider, SIGNAL(valueChanged(int)), pSpinBox, SLOT(setValue(int))); //创建布局 QHBoxLayout *pLayout = new QHBoxLayout; //向布局中添加控件 pLayout->addWidget(pSpinBox); pLayout->addWidget(pSlider); //对窗口使用布局 pWindow->setLayout(pLayout); pWindow->show(); return app.exec(); } |
下一篇: 2.1 子类化QDialog
上一篇: 1.2 建立连接