QApplication::setStyleでスタイルを変更することが出来ます。
C++
1QApplication::setStyle(QStyleFactory::create("Fusion"));
さらに、利用可能なスタイルはQStyleFactory::keysで確認できます。
何が使えるか表示するだけなら次のコードで充分です。
C++
1#include <QtCore/QDebug>
2#include <QtWidgets/QStyleFactory>
3
4int main(int argc, char *argv[]) {
5 qDebug() << QStyleFactory::keys();
6 return 0;
7}
実行結果
("Windows", "WindowsXP", "WindowsVista", "Fusion")
私の環境(Win10, Qt5.6.0, MSVC2015_64)ではMacスタイルは利用できないようです。
実際、リファレンスに次のような記述があります。
The valid keys can be retrieved using the keys() function. Typically they include "windows" and "fusion". Depending on the platform, "windowsxp", "windowsvista", "gtk" and "macintosh" may be available. Note that keys are case insensitive.
やはり、環境依存のようですね。
ところで
ここまで回答を書いて、一応ググってみたところ...
ほぼ同じ回答を発見してしまいました。stackoverflow - Application Window Style
Qt5 has new way to set style. For example:
C++
1QApplication a(argc, argv);
2qDebug() << QStyleFactory::keys();
3a.setStyle(QStyleFactory::create("Fusion"));
In my computer output is:
("Windows", "WindowsXP", "WindowsVista", "Fusion")
As you can see, mac os style is not available.
The QStyleFactory class creates QStyle objects.
The QStyle class is an abstract base class that encapsulates the look and feel of a GUI. QStyleFactory creates a QStyle object using the create() function and a key identifying the style. The styles are either built-in or dynamically loaded from a style plugin (see QStylePlugin).
The valid keys can be retrieved using the keys() function. Typically they include "windows" and "fusion". Depending on the platform, "windowsxp", "windowsvista", "gtk" and "macintosh" may be available. Note that keys are case insensitive.
ロジックの流れとコードが一致、引用箇所と強調部分もほぼ一致。
後からパクリと言われるのもあれなので、前もって書いてしまいました。
バッドをするには、ログインかつ
こちらの条件を満たす必要があります。
2017/11/01 03:11