#include <QApplication>
#include <QSlider>
#include <QSpinBox>
#include <QVBoxLayout>
#include <QLabel>
int main(int argc, char *argv[])
{
QApplication app(argc, argv);
QWidget *window = new QWidget;
window->setStyleSheet("QWidget{background-color:rgb(0,0,0);}");//用CSS设置QWidget表现
QSlider* slider = new QSlider(Qt::Horizontal,window);
slider->setRange(0,100);
QSpinBox* spinBox = new QSpinBox(window);
spinBox->setRange(0,100);
QLabel *label = new QLabel(window);
label->setStyleSheet("QLabel{font:45px;color:red;}");//用CSS设置label表现
QVBoxLayout *layout = new QVBoxLayout(window);
layout->addWidget(label);
layout->addWidget(slider);
layout->addWidget(spinBox);
//QObject::connect(slider,SIGNAL(valueChanged(int)),label,SLOT(setText(QString::number(int))));写成这样是不行的,因为参数不匹配,valueChanged(int)传的是int,setText()要的是QString,QT要求参数完全匹配,转换也不行
QObject::connect(slider,SIGNAL(valueChanged(int)),spinBox,SLOT(setValue(int)));
QObject::connect(slider,SIGNAL(valueChanged(int)),label,SLOT(setNum(int)));
QObject::connect(spinBox,SIGNAL(valueChanged(int)),slider,SLOT(setValue(int)));
QObject::connect(spinBox,SIGNAL(valueChanged(int)),label,SLOT(setNum(int)));
window->setLayout(layout);
window->setFixedSize(300,200);
window->show();
return app.exec();
}
Qt学习 第20节:setStyleSheet
最新推荐文章于 2024-05-16 09:53:47 发布