feat: v1.1 使用qApp->setStyle("xxx")显示系统其他风格
This commit is contained in:
parent
488485ee49
commit
e4872abf51
27
QtCustomStyleEx/ExMyStyle.cpp
Normal file
27
QtCustomStyleEx/ExMyStyle.cpp
Normal file
@ -0,0 +1,27 @@
|
|||||||
|
/*
|
||||||
|
* Copyright (C) 2019 ~ 2019 touwoyimuli. All rights reserved.
|
||||||
|
*
|
||||||
|
* Author: touwoyimuli <touwoyimuli@gmai.com>
|
||||||
|
*
|
||||||
|
* github: https://github.com/touwoyimuli
|
||||||
|
* blogs: https://touwoyimuli.github.io/
|
||||||
|
*
|
||||||
|
* This program is free software: you can redistribute it and/or modify
|
||||||
|
* it under the terms of the GNU General Public License as published by
|
||||||
|
* the Free Software Foundation, either version 3 of the License, or
|
||||||
|
* any later version.
|
||||||
|
*
|
||||||
|
* This program is distributed in the hope that it will be useful,
|
||||||
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
|
* GNU General Public License for more details.
|
||||||
|
*
|
||||||
|
* You should have received a copy of the GNU General Public License
|
||||||
|
* along with this program. If not, see <https://touwoyimuli.github.io/>.
|
||||||
|
*/
|
||||||
|
#include "ExMyStyle.h"
|
||||||
|
|
||||||
|
ExMyStyle::ExMyStyle()
|
||||||
|
{
|
||||||
|
|
||||||
|
}
|
34
QtCustomStyleEx/ExMyStyle.h
Normal file
34
QtCustomStyleEx/ExMyStyle.h
Normal file
@ -0,0 +1,34 @@
|
|||||||
|
/*
|
||||||
|
* Copyright (C) 2019 ~ 2019 touwoyimuli. All rights reserved.
|
||||||
|
*
|
||||||
|
* Author: touwoyimuli <touwoyimuli@gmai.com>
|
||||||
|
*
|
||||||
|
* github: https://github.com/touwoyimuli
|
||||||
|
* blogs: https://touwoyimuli.github.io/
|
||||||
|
*
|
||||||
|
* This program is free software: you can redistribute it and/or modify
|
||||||
|
* it under the terms of the GNU General Public License as published by
|
||||||
|
* the Free Software Foundation, either version 3 of the License, or
|
||||||
|
* any later version.
|
||||||
|
*
|
||||||
|
* This program is distributed in the hope that it will be useful,
|
||||||
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
|
* GNU General Public License for more details.
|
||||||
|
*
|
||||||
|
* You should have received a copy of the GNU General Public License
|
||||||
|
* along with this program. If not, see <https://touwoyimuli.github.io/>.
|
||||||
|
*/
|
||||||
|
#ifndef EXMYSTYLE_H
|
||||||
|
#define EXMYSTYLE_H
|
||||||
|
|
||||||
|
#include <QCommonStyle>
|
||||||
|
|
||||||
|
|
||||||
|
class ExMyStyle : public QCommonStyle
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
ExMyStyle();
|
||||||
|
};
|
||||||
|
|
||||||
|
#endif // EXMYSTYLE_H
|
@ -1,11 +1,69 @@
|
|||||||
|
/*
|
||||||
|
* Copyright (C) 2019 ~ 2019 touwoyimuli. All rights reserved.
|
||||||
|
*
|
||||||
|
* Author: touwoyimuli <touwoyimuli@gmai.com>
|
||||||
|
*
|
||||||
|
* github: https://github.com/touwoyimuli
|
||||||
|
* blogs: https://touwoyimuli.github.io/
|
||||||
|
*
|
||||||
|
* This program is free software: you can redistribute it and/or modify
|
||||||
|
* it under the terms of the GNU General Public License as published by
|
||||||
|
* the Free Software Foundation, either version 3 of the License, or
|
||||||
|
* any later version.
|
||||||
|
*
|
||||||
|
* This program is distributed in the hope that it will be useful,
|
||||||
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
|
* GNU General Public License for more details.
|
||||||
|
*
|
||||||
|
* You should have received a copy of the GNU General Public License
|
||||||
|
* along with this program. If not, see <https://touwoyimuli.github.io/>.
|
||||||
|
*/
|
||||||
#include "Example.h"
|
#include "Example.h"
|
||||||
|
|
||||||
Example::Example(QWidget *parent)
|
Example::Example(QWidget *parent)
|
||||||
: QWidget(parent)
|
: QWidget(parent)
|
||||||
{
|
{
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
Example::~Example()
|
Example::~Example()
|
||||||
{
|
{
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void Example::init()
|
||||||
|
{
|
||||||
|
QTableWidget *table = new QTableWidget(10, 10, this);
|
||||||
|
QProgressBar *progressH = new QProgressBar(this);
|
||||||
|
QProgressBar *progressV = new QProgressBar(this);
|
||||||
|
|
||||||
|
table->move(10, 10);
|
||||||
|
|
||||||
|
progressH->move(300, 50);
|
||||||
|
progressH->setRange(0, 100);
|
||||||
|
progressH->setValue(34);
|
||||||
|
progressH->resize(380, 40);
|
||||||
|
|
||||||
|
progressV->move(50, 250);
|
||||||
|
progressV->setRange(0, 100);
|
||||||
|
progressV->setValue(67);
|
||||||
|
progressV->resize(50, 380);
|
||||||
|
progressV->setOrientation(Qt::Vertical);
|
||||||
|
|
||||||
|
int i = 0;
|
||||||
|
QStringList listStyle = QStyleFactory::keys();
|
||||||
|
foreach(QString val, listStyle) { //打印当前系统支持的系统风格
|
||||||
|
QPushButton *btn = new QPushButton(val, this);
|
||||||
|
btn->move(this->rect().right() - 100, this->rect().top() + i++ * 40);
|
||||||
|
connect(btn, &QPushButton::clicked, this, [=](){
|
||||||
|
qApp->setStyle(val);
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
QPushButton *btn = new QPushButton("ExMyStyle", this);
|
||||||
|
btn->move(this->rect().right() - 100, this->rect().top() + i++ * 40);
|
||||||
|
connect(btn, &QPushButton::clicked, this, [=](){
|
||||||
|
qApp->setStyle(QStyleFactory::create("ExMyStyle"));
|
||||||
|
});
|
||||||
|
}
|
||||||
|
@ -22,7 +22,15 @@
|
|||||||
#ifndef EXAMPLE_H
|
#ifndef EXAMPLE_H
|
||||||
#define EXAMPLE_H
|
#define EXAMPLE_H
|
||||||
|
|
||||||
|
#include <QStyleFactory>
|
||||||
|
#include <QDebug>
|
||||||
#include <QWidget>
|
#include <QWidget>
|
||||||
|
#include <QTableWidget>
|
||||||
|
#include <QProgressBar>
|
||||||
|
#include <QPushButton>
|
||||||
|
#include <QApplication>
|
||||||
|
|
||||||
|
#include "ExMyStyle.h"
|
||||||
|
|
||||||
class Example : public QWidget
|
class Example : public QWidget
|
||||||
{
|
{
|
||||||
@ -31,6 +39,8 @@ class Example : public QWidget
|
|||||||
public:
|
public:
|
||||||
Example(QWidget *parent = 0);
|
Example(QWidget *parent = 0);
|
||||||
~Example();
|
~Example();
|
||||||
|
|
||||||
|
void init();
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif // EXAMPLE_H
|
#endif // EXAMPLE_H
|
||||||
|
@ -26,10 +26,13 @@ CONFIG += c++11
|
|||||||
|
|
||||||
SOURCES += \
|
SOURCES += \
|
||||||
main.cpp \
|
main.cpp \
|
||||||
Example.cpp
|
Example.cpp \
|
||||||
|
ExMyStyle.cpp
|
||||||
|
|
||||||
HEADERS += \
|
HEADERS += \
|
||||||
Example.h
|
Example.h \
|
||||||
|
ExMyStyle.h
|
||||||
|
|
||||||
|
|
||||||
# Default rules for deployment.
|
# Default rules for deployment.
|
||||||
qnx: target.path = /tmp/$${TARGET}/bin
|
qnx: target.path = /tmp/$${TARGET}/bin
|
||||||
|
@ -21,12 +21,24 @@
|
|||||||
*/
|
*/
|
||||||
#include "Example.h"
|
#include "Example.h"
|
||||||
#include <QApplication>
|
#include <QApplication>
|
||||||
|
#include <QStyleFactory>
|
||||||
|
#include <QDebug>
|
||||||
|
|
||||||
int main(int argc, char *argv[])
|
int main(int argc, char *argv[])
|
||||||
{
|
{
|
||||||
QApplication a(argc, argv);
|
QApplication a(argc, argv);
|
||||||
Example w;
|
|
||||||
w.show();
|
//若为系统自带的QStyle,则qApp->setStyle("系统自带风格");
|
||||||
|
//若为自定义新的QStyle,则qApp->setStyle(QStyleFactory::create("自定义风格"))
|
||||||
|
QStringList listStyle = QStyleFactory::keys();
|
||||||
|
foreach(QString val, listStyle) //打印当前系统支持的系统风格
|
||||||
|
qDebug()<<val<<" ";
|
||||||
|
|
||||||
|
qApp->setStyle("chameleon"); //Windows/Fusion/...
|
||||||
|
Example *w = new Example();
|
||||||
|
w->resize(1000, 700);
|
||||||
|
w->init();
|
||||||
|
w->show();
|
||||||
|
|
||||||
return a.exec();
|
return a.exec();
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user