3

Though my operating system is Windows, I want my application to look like a Mac application. I know I can easily change that style using QApplication::setStyle.

QApplication::setStyle(new QWindowsVistaStyle)

I know Qt provide MacStyle too so, for MacStyle

QApplication::setStyle(new QMacStyle)

However, it seems QMacSytle is not declared. Compiler doesn't recognize it. And the Qt Webpage says

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

Is there any other way to use that Mac OS style window? Because I need to use that.

Iuliu
  • 4,001
  • 19
  • 31
user3734823
  • 99
  • 1
  • 1
  • 10
  • 2
    You can't use platform-specific style on non-supported platforms, because `QMacStyle` use native OS X API. Warning is correct. Just read and understand it. You may create your own QStyle for windows that looks like OS X style, but it requires years of work for a single developer. – Dmitry Sazonov Dec 30 '14 at 13:10

1 Answers1

17

Qt5 has new way to set style. For example:

QApplication a(argc, argv);
qDebug() << QStyleFactory::keys();
a.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.

Jablonski
  • 18,083
  • 2
  • 46
  • 47
  • If you don't use Qt5, tell me it please, because this answer valid only for Qt5 – Jablonski Dec 30 '14 at 09:35
  • Still, you cannot use OSX theme on Windows. – el.pescado - нет войне Dec 30 '14 at 14:05
  • @el.pescado because it is impossible and I proved that(description from official documentation, the most important part I wrote with bold font)What is wrong in my answer exactly?I can't understand – Jablonski Dec 30 '14 at 14:42
  • @Chernobyl Your answer is quite nice. Perhaps the down-vote is because you didn't highlight that it's impossible. I would suggest you start the first paragraph with something like: "Sorry but it's not possible to use OSX them on Windows" and discuss later how you can prove it by using style keys and documents. The original answer starting form "Qt 5 has new way to set style..." might be a little bit misleading since people would think it's possible at first place. – Tay2510 Dec 31 '14 at 03:39