How can I compile Qt app in Linux using Windows style? - qt

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.

Related

can my Qt Application get Mac look on windows

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.

Google NaCl with Qt on Windows

I have a project which is using Qt 4.7.4 version (also I can't rebuild it using qt4.8 or qt5 – there are a lot of errors appears, project is big and not mine so fixing issues would be even harder than erasing the whole code and write new code). So I need to make this project, well, working on NativeClient.
Is it even possible? I use Windows and Visual Studio, I was trying to google instructions about qt+nacl on Windows but just can’t find nothing.
Also which pepper version should I use if it depends on it?
Is your qt build supporting native client?
Please check out this
Windows
The Qt-Nacl is not support, for now, in Windows.
By the way, here is the github repository dedicated for it -> https://github.com/msorvig/qt5-qtbase-nacl
In the file nacl-readme it is written :
[...] Windows is not supported as a host platform.
Linux
If you want to compile in Linux, I have made a script that will compile Qt5.4 with NaCl with all the dependencies needed.
https://gist.github.com/theshadowx/438297ac465874a5e226
I also made a video that will show the different steps and a showCase at the end :
https://www.youtube.com/watch?v=q2pMv1Svtqw

Test WinXP look on other platforms?

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.

Qt: Enumerating Windows on the desktop(s)

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 . . .

Is there a way to run Qt Creator from command line supplying a .pro file to open (or how do we deal with multiple Qt installations)?

I have multiple installations of Qt4 on my Windows XP SP2 machine and have installed Qt Creator 2.1 today. However, running the project (.pro) files spawns the oldest version of Qt Designer installed (the one installed in 2009 together with the rest of the framework).
Since
I would not like to remove any previous installations of Qt
and for some obscure reason even if I explicitly ask Windows Explorer to always use the version I need it does not
I would like to give up a bit and just sript the needed behaviour in a .bat file like:
e:\path\to\qtcreator.exe %1
This opens Qt Creator, but something seems to prevent it from treating the .pro file properly (in short, the project does not "open" as it should).
Qt documents have a page on the matter at Qt Creator: Using Command Line Options, but it seems to ignore the topic in question.
Since Qt (being as excellent framework as it is) is also known to have its quirks (like that of qmake), I wonder, may be there is an undocumented way to solve my problem?
(Another way to fix the thing would of course be to make the correct version of Qt Designer run, but frankly I'd prefer the "hard-wired" solution since the mechanisms provided by Qt itself are still a bit unreliable.)
The libraries and tools used for a particular project (and a configuration in it) is set in the Projects panel in Qt Creator:
http://doc.qt.io/qtcreator/creator-build-settings.html
Selecting the Qt version to use with a project should force it to run the Designer that's part of the version. If it doesn't, then you should report it as a bug.

Resources