mirror of
https://github.com/XMuli/QtExamples.git
synced 2026-10-23 08:49:43 +08:00
feat: 创建系统自定义样式风格ExCustomStyle
搭建一个框架,但是继承的类QCommonStyle里面的对应的虚函数还有没有重写,和体验感受win和linux系统自带多种风格样式
This commit is contained in:
@@ -1,15 +1,53 @@
|
||||
#include "Examples.h"
|
||||
#include "ui_Examples.h"
|
||||
|
||||
CUSTOMSTYLE_USE_NAMESPACE
|
||||
|
||||
Examples::Examples(QWidget *parent) :
|
||||
QWidget(parent),
|
||||
ui(new Ui::Examples)
|
||||
{
|
||||
ui->setupUi(this);
|
||||
setWindowTitle(QObject::tr("创建自定义的CustomStyle风格"));
|
||||
|
||||
init();
|
||||
}
|
||||
|
||||
Examples::~Examples()
|
||||
{
|
||||
delete ui;
|
||||
}
|
||||
|
||||
//获取当前系统支持的默认系统风格
|
||||
void Examples::init()
|
||||
{
|
||||
//当前系统支持的系统风格,放入QcomboBox的item里面,且打印出来
|
||||
QStringList listStyle = QStyleFactory::keys();
|
||||
foreach(QString val, listStyle) {
|
||||
ui->comboBox->addItem(val);
|
||||
qDebug()<<val;
|
||||
}
|
||||
|
||||
//设置一个默认的风格
|
||||
ui->comboBox->addItem("ExCustomStyle");
|
||||
qApp->setStyle(QStyleFactory::create("Fusion"));
|
||||
}
|
||||
|
||||
|
||||
void Examples::on_comboBox_currentIndexChanged(const QString &style)
|
||||
{
|
||||
// qDebug()<<"当前选中的风格:"<<style;
|
||||
//当前选中item项为系统预支持的风格
|
||||
QStringList listStyle = QStyleFactory::keys();
|
||||
foreach(QString val, listStyle) {
|
||||
if (style == val) {
|
||||
qApp->setStyle(QStyleFactory::create(style));
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
//不属于系统风格,则使用自己的风格
|
||||
ExCustomStyle* customStyle = new ExCustomStyle;
|
||||
qApp->setStyle(customStyle);
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user