c++ - 应用程序窗口样式

标签 c++ qt qstyle

虽然我的操作系统是 Windows,但我希望我的应用程序看起来像 Mac 应用程序。我知道我可以使用 QApplication::setStyle 轻松更改该样式。

QApplication::setStyle(new QWindowsVistaStyle)

我知道 Qt 也提供 MacStyle,对于 MacStyle

QApplication::setStyle(new QMacStyle)

但是,QMacSytle 似乎没有声明。编译器无法识别它。 Qt 网页显示

Warning: This style is only available on Mac OS X because it relies on the HITheme APIs.

还有其他方法可以使用 Mac OS 风格的窗口吗?因为我需要使用它。

最佳答案

Qt5 具有设置样式的新方法。例如:

QApplication a(argc, argv);
qDebug() << QStyleFactory::keys();
a.setStyle(QStyleFactory::create("Fusion"));

在我的电脑输出是:

("Windows", "WindowsXP", "WindowsVista", "Fusion")

如您所见,mac os 样式不可用。

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.

关于c++ - 应用程序窗口样式,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/27702635/

相关文章:

c++ - Qt 多线程 QThreads 保持 TCP 连接并被重用

qt - 为什么Qt中使用parens reinterpret_cast< int(*)>

python - 从 QComboBox 中的样式列表中使用 QStyleFactory 设置样式

qt - 如何在 QStyledItemDelegate 中绘制正确的文本颜色

c++ - 如何用 C++ 绘制音频文件的振幅?

c++ - 在哪里保存 QWidget 动画的状态以便在 QStyle 绘制函数中使用?

.net - native C++ 应用程序的 list ?

c++ - 无法将虚函数移到 header 之外

c++ - 使用 MPL 创建所有模板排列

c++ - 为什么C++没有方便的方式为多维数组动态分配内存?