Qt6 platform rendering issues on Ubuntu 22.04
-
After updating my C++ desktop application to build with Qt 6.5, I noticed strange changes in the rendering of the widgets. For example, there are no window borders, and setting
enabled = false
for labels, etc. does not make them appear disabled. I have to add a command-line option-platform xcb
to run my app in order to see the title bar.Here are the screenshots of the different ways the main window is rendered for comparison:
-
Built with Qt 5.15.5:
-
Built with Qt 6.5, default appearance (no command-line option) ... notice how there is no window border:
-
Built with Qt 6.5, command-line option
-platform xcb
added:
Notice that on Qt 5, my "To do" list is nicely set to disabled gray look, whereas all labels look enabled with Qt 6 in both renderings.
What is the least intrusive way of making the newer versions look like the older ones?
-
-
Here is a screenshot with an active database in the app built with Qt 5.15, showing the "To do" list with different stages enabled and disabled:
-
Hi,
Do you have the same issue if you use the fusion style ?
By the way, which desktop environment are you using ?
-
@SGaist Thanks for looking at this. I am basically running a default desktop which Ubuntu 22.04 has configured. I don't really know what I am doing here, since I never changed anything. But I saw somewhere references to environment variables beginning with
XDG_...
, so here are the results of a few of those:bob@bobs-laptop:~$ echo $XDG_SESSION_TYPE wayland bob@bobs-laptop:~$ echo $XDG_SESSION_DESKTOP ubuntu bob@bobs-laptop:~$ echo $XDG_CURRENT_DESKTOP ubuntu:GNOME
If I give this option on the command line:
-patform xcb
as mentioned above, are there any options I can add after that? I looked all over but could not find any documentation about what the allowed options are, except for-platform windows
which has a lot of extra options.As to
fusion
, I get a fatal error when I put ? -platform fusion` on the command line:This application failed to start because no Qt platform plugin could be initialized. Reinstalling the application may fix this problem. Available platform plugins are: xcb, offscreen, minimal, vkkhrdisplay, eglfs, vnc, linuxfb, wayland, minimalegl, wayland-egl.
What do I need to do in order to get
fusion
to work? -
@SGaist I found out how to set the "Fusion" style here in another forum thread.
So I added this line to my
main()
function right after creating the instance of QApplication:qApp->setStyle(QStyleFactory::create("Fusion"));
It doesn't have any effect, AFAICT.
-
@Robert-Hairgrove I just wrote a small test program to confirm that qlabel is greyed out if it is disabled. Qt: 6.5.2 and OS: Ubuntu 22.04.
-
@Robert-Hairgrove
main.cpp#include "helpwidget.h" #include <QApplication> int main( int argc, char *argv[] ) { QApplication app(argc, argv); auto widget = new HelpWidget; widget->show(); return app.exec(); }
helpwidget.h
#ifndef HELPWIDGET_H #define HELPWIDGET_H #include <QWidget> //! [0] class HelpWidget : public QWidget { Q_OBJECT public: HelpWidget(QWidget *parent = nullptr); }; //! [0] #endif // HelpWidget_H
helpwidget.cpp
#include <QVBoxLayout> #include <QLabel> #include <QPushButton> #include "helpwidget.h" HelpWidget::HelpWidget( QWidget * parent ) : QWidget(parent) { auto layout = new QVBoxLayout( this ); setMinimumSize( 400, 400 ); auto label = new QLabel( "Dis/enabled test", this ); auto button = new QPushButton( "Press", this ); layout->addWidget( label ); layout->addWidget( button ); connect( button, &QPushButton::pressed, [=](){ auto isEnabled = label->isEnabled(); label->setEnabled( !isEnabled ); } ); }
-
@Robert-Hairgrove There you.
testlabel.proQT += widgets HEADERS += \ helpwidget.h SOURCES += \ helpwidget.cpp \ main.cpp
-
@JoeCFD Your code builds and runs OK, but when I click on the "Press" button, the label does not change its appearance.
Please post the results of the following commands run in a terminal:
echo $XDG_SESSION_TYPE echo $XDG_SESSION_DESKTOP echo $XDG_CURRENT_DESKTOP
Also:
echo $QT_QPA_PLATFORM
Thank you!
-
@Robert-Hairgrove
x11
Lubuntu
LXQt
empty -
@Robert-Hairgrove
@SGaist understands this much better than I do, but is your picture #2 (no borders and Qt6.5) somehow "wayland"? Which might not have/do the effects of x11/xcb? -
I forgot to add that the precise version of Qt I have is 6.5.3 which was installed automatically by the Qt Creator maintenance tool.
-
@Robert-Hairgrove I guess the problem should be gone if you switch to X11. Do you have to use Wayland? Wayland is the default setting in Ubuntu 22.04.
-
@Robert-Hairgrove logout your account. You can see a settings icon on the login screen and click the setting icon to select Xorg. Then log in and you will be good.