2019-08-26 19:22:02 +08:00
|
|
|
#include "Examples.h"
|
|
|
|
#include "ui_Examples.h"
|
|
|
|
|
2019-08-29 23:26:30 +08:00
|
|
|
CUSTOMSTYLE_USE_NAMESPACE
|
|
|
|
|
2019-08-26 19:22:02 +08:00
|
|
|
Examples::Examples(QWidget *parent) :
|
|
|
|
QWidget(parent),
|
|
|
|
ui(new Ui::Examples)
|
|
|
|
{
|
|
|
|
ui->setupUi(this);
|
|
|
|
setWindowTitle(QObject::tr("创建自定义的CustomStyle风格"));
|
2019-08-29 23:26:30 +08:00
|
|
|
|
|
|
|
init();
|
2019-08-26 19:22:02 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
Examples::~Examples()
|
|
|
|
{
|
|
|
|
delete ui;
|
|
|
|
}
|
2019-08-29 23:26:30 +08:00
|
|
|
|
|
|
|
//获取当前系统支持的默认系统风格
|
|
|
|
void Examples::init()
|
|
|
|
{
|
|
|
|
//当前系统支持的系统风格,放入QcomboBox的item里面,且打印出来
|
|
|
|
QStringList listStyle = QStyleFactory::keys();
|
|
|
|
foreach(QString val, listStyle) {
|
|
|
|
ui->comboBox->addItem(val);
|
|
|
|
qDebug()<<val;
|
|
|
|
}
|
|
|
|
|
|
|
|
//设置一个默认的风格
|
|
|
|
ui->comboBox->addItem("ExCustomStyle");
|
2019-09-10 22:36:14 +08:00
|
|
|
// qApp->setStyle(QStyleFactory::create("Fusion"));
|
|
|
|
qApp->setStyle(new ExCustomStyle());
|
2019-08-29 23:26:30 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
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);
|
|
|
|
|
|
|
|
}
|