As Qt application will be in native look and feel.
I want to get mac look and feel for my Qt application. Is it possible to do so?
It is possible to change look and feel of Qt application by using styles:
QApplication::setStyle("macintosh");
List of available styles is given by:
QStringList list = QStyleFactory::keys();
But for example on Windows Mac style is typically unavailable. I tested on Windows machine with Qt 5.4 - only Windows (Windows, WindowsXP and WindowsVista) and Fusion styles are available - you can switch between them.
Of course, Windows style is default for Windows. It is advised to set style before constructing QApplication.
Related
I'm developing one GUI app (among others) in Python with PySide2 and my main editor is VSCode and I'd like to keep it this way - I'm using the standalone Qt Designer for GUI layout calling it from VSCode when necessary.
I see that the full Qt Creator has a way to select couple of different dark modes in its IDE settings, however I see no such possibility in the Qt Designer launched as standalone application.
I develop on Windows 10 by the way and setting its dark mode doesn't change how Qt Designer looks, it keeps its Windows Vista look:).
Is there something that can be done, maybe a command line parameter?
I am trying to make my GTK3 application look native on Windows 7. I tried the answer in the following question How to get native windows decorations on GTK3 on Windows 7+ and MSYS2
But it doesn't work. My GTK3 version on windows is 3.22 and I am using the Vala language. Tried with GTK3 version 3.20 to no avail either. I also tried changing the background color of the application in the code itself with the CssProvider and it works in Ubuntu, but not in Windows. In Windows, the application theme and all CSS manual settings are ignored.
Is there any way to achieve this? Thanks.
It worked by calling in the code, before displaying the main application window with show_all () :
Gtk.Settings.get_default ().gtk_theme_name = "win32";
When using a custom theme, the location of the theme should be: "YourApplicationExecutable\share\themes\ThemeFolder" as per described in the accepted answer of How to get native windows decorations on GTK3 on Windows 7+ and MSYS2
and the name set with gtk_theme_name in the code should be the name of the folder containing the theme.
Note that the method get_default () gets you the default GDK screen. If you want more control over specific widgets, use instead the method get_settings () over the specific widget that you want to change the theme for.
Sources:
How to get native windows decorations on GTK3 on Windows 7+ and MSYS2
https://valadoc.org/gtk+-3.0/Gtk.CssProvider.html
https://valadoc.org/gtk+-3.0/Gtk.Settings.html
I'm developing a Qt Widgets application and due to compile performance issues, I started developing it in Linux Ubuntu instead of Windows. The problems is that, when compiled and run, the app appears with traditional Ubuntu style instead of Windows (7) style. Since the app is only for Windows, I'ld like to know how can I compile it inside Linux Ubuntu but making it appear with Windows style.
I tried using QApplication::setStyle(QStyleFactory::create("QWindowsStyle")); in main.cpp, without success. I guess the QtAssistant docs just aren't clear enough on how can I do this change. Any help will be appreciated.
Could you by any chance be using a Qt package that is compiled without the style? Can you try running QStyleFactory::keys() to verify that the style exists?
It can't be done, since the style's elements are rendered by Windows (or OS X), not by Qt. Qt's style implementation asks the OS libraries to provide bitmaps of those elements. If you wanted to, you could modify the style to use a disk cache for static items. You could then use the style on all platforms. The problem is that these OS-provided bitmaps are a part of the OS and thus non-redistributable.
The only plastform-specific style that at least used to be available everywhere was the old Windows 95 style, in times of Qt 3. I'm not sure what its current status is.
First check out put of QStyleFactory::keys()
then set the look by calling
qApp->setStyle("Windows");
This command will give you windows 98 look. If you want windows vista look you should configure qt sources with -style-windowsvista and rebuild all sources.
UPDATE
according to http://doc.qt.io/qt-5/qstylefactory.html#details qt style is not platform independent. So IT IS IMPOSSIBLE to have that native look in not windows platform. It's worth mentioning that in windows also Windows SDK itself is required in order to build sources of Qt otherwise your application will look like windows 98 in windows 7.
Is there a way to test the look of my UI on Windows or other platforms from my Linux machine? I'd like to have some idea of how it will look without having to rebuilding the project on a windows machine.
At the command line for your program you can specify the style:
http://qt-project.org/doc/qt-5.0/qtwidgets/qapplication.html#QApplication
-style= style, sets the application GUI style. Possible values depend on your system configuration. If you compiled Qt with additional styles or have additional styles as plugins these will be available to the -style command line option. You can also set the style for all Qt applications by setting the QT_STYLE_OVERRIDE environment variable.
In some older documentation it mentions:
Possible values are motif, windows, and platinum.
I just tried this on Windows 8 with Qt 4.8.4, and I got no change adding in "style=platinum" or any of the others, and apparently the build of Qt that I got did not come with the additional style plugins. So, build Qt with the additional styles, and then you can preview the look for other OS's.
Hope that helps.
My Qt application (that will run on Windows, OS X and Ubuntu) has a need to:
List all windows everywhere
Obtain their caption text (if any)
Obtain an Icon of the application, if any, as QIcon or QPixmap (e.g. App Icon)
Obtain some kind of unique ID about them (e.g. HWND on windows)
I know how to do this for Windows using Win32. I can research Mac and Ubuntu separately, but I was wondering if there's an abstracted/unified Qt approach to assist me?
Nope, those are OS specific:
http://www.qtcentre.org/threads/41730-How-to-enumerate-all-top-level-windows
As for starting down the quest of what's doable through published APIs...some X11 hints here:
How to identify top-level X11 windows using xlib?
On Macs, the "forward-looking" way to build Qt is against "Cocoa" instead of "Carbon":
http://doc.qt.nokia.com/latest/developing-on-mac.html#carbon-or-cocoa
And according to other SOers, it's the accessibility API (which has to be enabled by users, it seems) that can do this enumeration:
Get a list of opened windows cocoa
Mac / Cocoa - Getting a list of windows using Accessibility API
Then the question becomes how inside of a C++ application to make "calls out" to Cocoa APIs which are natively Objective-C:
How to mix Qt, C++ and Obj-C/Cocoa
...or you could just not do this. :-)
I would suggest keeping track of this information yourself. It wouldn't be perfect (just have a singleton class and overload the setWindowTitle() calls in your root window types) but would be platform-independent . . .