How can I ensure that the text in the QTabBar of QDockWidgets is not cut off?
-
Hi all,
I have a program that has a bunch of QDockWidgets with quite complex widgets inside. At startup, the docks are arranged as tabs and hidden, and some "welcome" screen is shown, with shortcut buttons to create a new database or load one. If one creates or loads a database, the welcome widget is hidden and the docks are shown.
With Qt 5, the tab bar looks like this:
When built using Qt 6, the text of the middle tab is cut off:
I tried hard to strip this down to a minimal example, but I can't reproduce this with minimal code. I suppose this is some timing problem, some widget not yet shown or some geometry not updated correctly or whatever. As said: If I create a minimal example with a welcome widget with a button, three docks, using the very same text and the button hiding the welcome screen and showing the docks (which is essentially the same what happens when loading a database), the text is not cut off.
However, if I change the title of the middle dock a bit, it's also not cut off:
Adding a single space or even a "hair space" (\u200A) is already enough to make it appear completely, not cut off.
If I don't hide the docks, the text is not cut off. Also, if I hide the docks not directly, but using a QTimer::singleShot with a 100 ms delay, the tab is rendered correctly:
Interestingly, using a singleShot call with a 0 ms delay does not fix it, the text is also cut off in this case.
This may or not may be a bug, a race condition, depend on the very font I use or whatever. But is there any way to ensure that the tab text is not cut off? There seems to be no way to access the QTabBar of the docks?
Thanks for all help and all hints!
-
Also seems to be some font metrics problem … I see this using Noto Sans at 10pt. Not at 9, and not at 11. Also not with e.g. Dejavu Sans.
However, a Qt 5.15 build displays the whole tab, whereas a Qt 6.7 build cuts the text off.
… but why does this not happen if I hide the docks with a small delay?! Using the very same font settings?
-
Woah, this is one strange thing. Here's some minimal example that produces this exact behavior, using Noto Sans 10 pt. Seems to depend on the menu and also on the texts used. If you e.g. the fourth menu entry "X" and not "Extras", the "Ergebnisse" tab is not cut off.
CMakeLists.txt:
cmake_minimum_required(VERSION 3.22.0) project(demo CXX) find_package(Qt6 COMPONENTS Widgets) set(CMAKE_AUTOMOC ON) add_executable(demo ${CMAKE_SOURCE_DIR}/main.cpp ${CMAKE_SOURCE_DIR}/MainWindow.cpp) target_link_libraries(demo PRIVATE Qt6::Widgets)
main.cpp:
#include "MainWindow.h" #include <QApplication> int main(int argc, char *argv[]) { QApplication app(argc, argv); MainWindow mainWindow; mainWindow.show(); return app.exec(); }
MainWindow.h:
#ifndef MAINWINDOW_H #define MAINWINDOW_H #include <QMainWindow> class MainWindow : public QMainWindow { Q_OBJECT public: explicit MainWindow(); }; #endif // MAINWINDOW_H
MainWindow.cpp:
#include "MainWindow.h" #include <QVBoxLayout> #include <QPushButton> #include <QDockWidget> #include <QMenuBar> MainWindow::MainWindow() : QMainWindow() { auto *splash = new QWidget(this); setCentralWidget(splash); auto *layout = new QVBoxLayout(splash); auto *button = new QPushButton(tr("Show")); layout->addWidget(button); setDockNestingEnabled(true); auto *players = new QDockWidget(tr("Anmeldung"), this); addDockWidget(Qt::TopDockWidgetArea, players); auto *score = new QDockWidget(tr("Ergebnisse"), this); addDockWidget(Qt::TopDockWidgetArea, score); tabifyDockWidget(players, score); auto *ranking = new QDockWidget(tr("Rangliste"), this); addDockWidget(Qt::TopDockWidgetArea, ranking); tabifyDockWidget(score, ranking); menuBar()->addMenu(tr("Datei")); menuBar()->addMenu(tr("Ansicht")); menuBar()->addMenu(tr("Netzwerk")); menuBar()->addMenu(tr("Extras")); players->hide(); score->hide(); ranking->hide(); connect(button, &QPushButton::clicked, this, [this, splash, players, score, ranking] { splash->hide(); players->show(); score->show(); ranking->show(); }); resize(QSize(500, 200)); }
Result after clicking "Show":
-
What style do you use? I can't reproduce it with fusion - looks like breeze (which is not provided by Qt but someone else). You should report it there.
-
hello, unfortunatly, just mine doesn't cut off, but If you wanna fix this problem, I will give you two advice.
First, to set the minimum size to tabwidget using method 'setMinimumSize'.
Second, to reimplement the tabwidget and to set the reimplemented widget to tabwidget. you may reimplemented it with QMetricFont -
Also tried it with Qt6.9 on Linux (added
app.setFont(QFont("Noto Sans", 10));
after QApplication ctor) and it works fine there too. -
Also tried it with Qt6.9 on Linux (added
app.setFont(QFont("Noto Sans", 10));
after QApplication ctor) and it works fine there too.@Christian-Ehrlicher Qt 6.9? I Thought we are at 6.7.2?
However this is really odd. Are you on Plasma 6.1.1? What can cause this?! I would expect some local configuration problem if this was only on one of my machines, but on two different distribution?
How can one track this down?!
-
@Christian-Ehrlicher Qt 6.9? I Thought we are at 6.7.2?
However this is really odd. Are you on Plasma 6.1.1? What can cause this?! I would expect some local configuration problem if this was only on one of my machines, but on two different distribution?
How can one track this down?!
@l3u_ said in How can I ensure that the text in the QTabBar of QDockWidgets is not cut off?:
I Thought we are at 6.7.2?
I only test with current Qt git version.
I use plasma 5 I guess (did not update openSUSE recently).How can one track this down?!
Only by building Qt by yourself and adding some debug output in the appropriate places (I would guess inside QCommonStyle.cpp)
-
@l3u_ said in How can I ensure that the text in the QTabBar of QDockWidgets is not cut off?:
I Thought we are at 6.7.2?
I only test with current Qt git version.
I use plasma 5 I guess (did not update openSUSE recently).How can one track this down?!
Only by building Qt by yourself and adding some debug output in the appropriate places (I would guess inside QCommonStyle.cpp)
@Christian-Ehrlicher Okay, I now tested it.
I setup the current KUbuntu in a QEMU VM. This one ships with a Plasma 5 desktop. Both the Qt 5 and the Qt 6 build of my demo don't show the problem.
I then setup current OpenSUSE Tumbleweed, also in a QEMU VM. Here, we have a Plasma 6 desktop. The result is the very same as with my desktop: When building with Qt 5, everything is fine. But a Qt 6 build results in that very problem that the text is being cut off.
So, this seems to depend on the window manager? Or the whole desktop? Seems to be a KDE problem after all …
-
I now filed a KDE bug about this compiling everything I could find out: https://bugs.kde.org/show_bug.cgi?id=489516