您的位置:首页 > 编程语言 > Qt开发

Qt学习之路(3):布局

2015-12-20 19:32 483 查看

布局可以使得控件随着窗口的变化而变化。

#include <QApplication>
#include "QSpinBox"
#include "QWidget"
#include "QSlider"
#include "QHBoxLayout"
#include "QStyle"
#include "memory"
int main(int argc, char *argv[])
{
QApplication a(argc, argv);
//QApplication::setStyle("plastique");

QWidget window;
window.setAutoFillBackground(true);
window.setWindowIcon(QIcon(":/image/rose"));
QPalette palette;
palette.setColor(QPalette::Background, QColor(180,200,100));//
//palette.setBrush(QPalette::Background, QBrush(QPixmap(":/image/rose")));
window.setPalette(palette);
window.setWindowTitle("Enter your age");//指定窗口名字
auto *spinBox = new QSpinBox(&window);//该box作为window的子对象
auto slider = new QSlider(Qt::Horizontal,&window);//该slider作为window的子对象
spinBox->setRange(0,130);
slider->setRange(0,130);
QObject::connect(slider,QSlider::valueChanged,spinBox,QSpinBox::setValue);
void (QSpinBox:: *spinBoxSignal)(int) = &QSpinBox::valueChanged;//显式的指定函数指针
QObject::connect(spinBox,spinBoxSignal,slider,QSlider::setValue);
spinBox->setValue(35);
auto layout = new QHBoxLayout;//创建一个水平布局
layout->addWidget(spinBox);
layout->addWidget(slider);
window.setLayout(layout);
window.show();

return a.exec();
}




======================================================================================
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: