Reputation: 93
I am trying to build a Qt app on Windows 10 and I get a different appearance when I run it from the Qt Creator IDE, and when I run the exe outside of it.
From Qt Creator
Outside Qt Creator
I'd like to have it always look the way it does within Qt Creator: a better looking button and no superfluous second window.
Replication: Create a new project in Qt Creator (a Qt Widgets application) with CMake as build system and the Desktop Qt 5.15.0 MSVC2019 64bit kit. Add the button to the .ui with the designer and compile. To get the application running outside the IDE, put beside it the dlls Qt5Cored.dll, Qt5Guid.dll, Qt5Widgetsd.dll, and platforms/qwindowsd.dll, all got from the 5.15.0/msvc2019_64 folder in the Qt installation.
Edit: It appears the superfluous window only appears if I use CMake, it doesn't occur with projects made with qmake. However, I'm adding a GUI to an already existing project, so 'use qmake' isn't a solution.
Upvotes: 1
Views: 1046
Reputation: 93
The console window problem was caused by the lack of a WIN32 argument to add_executable
as stated in Swift's answer. However, the theme issue was caused by something different.
Going by this thread, it appears that as of Qt 5.14, if the dlls of an executable are stored beside it and there is no styles folder then the Windows theme (which looks like Windows 95) is used. However, adding the dll styles/qwindowsvistastyled.dll fixes this issue.
Upvotes: 1
Reputation: 14589
The nature of Qt environment is such that if you didn't specify that in program code, Qt inherits style from environment it was run in. See QApplication
, -style
command line flag.
Qt Creator is written in Qt and it sounds like it got a non-default style set in your installation. When you preview a form from QT Designer you can choose which style that form should be displayed in.
It looks like console window can be a result of CMake project setting, e.g. add_executable
was called without WIN32 argument.
https://cmake.org/cmake/help/latest/command/add_executable.html
It could be also created by something in project, e.g. if there is a framework which initializes Console API.
Upvotes: 3