Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. How can I ensure that the text in the QTabBar of QDockWidgets is not cut off?
Forum Updated to NodeBB v4.3 + New Features

How can I ensure that the text in the QTabBar of QDockWidgets is not cut off?

Scheduled Pinned Locked Moved Unsolved General and Desktop
13 Posts 3 Posters 1.4k Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • l3u_L Offline
    l3u_L Offline
    l3u_
    wrote on last edited by l3u_
    #1

    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:

    1.png

    When built using Qt 6, the text of the middle tab is cut off:

    2.png

    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:

    3.png

    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:

    4.png

    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!

    1 Reply Last reply
    0
    • l3u_L Offline
      l3u_L Offline
      l3u_
      wrote on last edited by
      #2

      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?

      1 Reply Last reply
      0
      • l3u_L Offline
        l3u_L Offline
        l3u_
        wrote on last edited by l3u_
        #3

        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":

        1.png

        1 Reply Last reply
        0
        • Christian EhrlicherC Offline
          Christian EhrlicherC Offline
          Christian Ehrlicher
          Lifetime Qt Champion
          wrote on last edited by
          #4

          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.

          Qt Online Installer direct download: https://download.qt.io/official_releases/online_installers/
          Visit the Qt Academy at https://academy.qt.io/catalog

          1 Reply Last reply
          0
          • l3u_L Offline
            l3u_L Offline
            l3u_
            wrote on last edited by
            #5

            Happens both with Breeze and Fusion:

            1.png

            But only with Noto Sans 10pt set as the font. Does not happen with another font or another size. I can produce this both on my Gentoo desktop system and on my Artix notebook, with exactly the same result.

            1 Reply Last reply
            0
            • C Offline
              C Offline
              Crimson
              wrote on last edited by
              #6

              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

              1 Reply Last reply
              0
              • l3u_L Offline
                l3u_L Offline
                l3u_
                wrote on last edited by l3u_
                #7

                That's the problem: This is not a QTabWidget, those are QDockWidgets – with no means to access the QTabBar in question :-(

                1 Reply Last reply
                0
                • Christian EhrlicherC Offline
                  Christian EhrlicherC Offline
                  Christian Ehrlicher
                  Lifetime Qt Champion
                  wrote on last edited by
                  #8

                  Also tried it with Qt6.9 on Linux (added app.setFont(QFont("Noto Sans", 10));after QApplication ctor) and it works fine there too.

                  Qt Online Installer direct download: https://download.qt.io/official_releases/online_installers/
                  Visit the Qt Academy at https://academy.qt.io/catalog

                  l3u_L 1 Reply Last reply
                  0
                  • Christian EhrlicherC Christian Ehrlicher

                    Also tried it with Qt6.9 on Linux (added app.setFont(QFont("Noto Sans", 10));after QApplication ctor) and it works fine there too.

                    l3u_L Offline
                    l3u_L Offline
                    l3u_
                    wrote on last edited by
                    #9

                    @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 EhrlicherC 1 Reply Last reply
                    0
                    • l3u_L l3u_

                      @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 EhrlicherC Offline
                      Christian EhrlicherC Offline
                      Christian Ehrlicher
                      Lifetime Qt Champion
                      wrote on last edited by
                      #10

                      @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)

                      Qt Online Installer direct download: https://download.qt.io/official_releases/online_installers/
                      Visit the Qt Academy at https://academy.qt.io/catalog

                      l3u_L 1 Reply Last reply
                      0
                      • l3u_L Offline
                        l3u_L Offline
                        l3u_
                        wrote on last edited by
                        #11

                        Well, maybe then it's the combination of Qt 6 and the Plasma 6 desktop. I'll have to see if I can check this on a Plasma 5 desktop. Maybe inside some virtual machine or so.

                        However this is really weird.

                        1 Reply Last reply
                        0
                        • Christian EhrlicherC Christian Ehrlicher

                          @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_L Offline
                          l3u_L Offline
                          l3u_
                          wrote on last edited by
                          #12

                          @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 …

                          1 Reply Last reply
                          0
                          • l3u_L Offline
                            l3u_L Offline
                            l3u_
                            wrote on last edited by
                            #13

                            I now filed a KDE bug about this compiling everything I could find out: https://bugs.kde.org/show_bug.cgi?id=489516

                            1 Reply Last reply
                            0

                            • Login

                            • Login or register to search.
                            • First post
                              Last post
                            0
                            • Categories
                            • Recent
                            • Tags
                            • Popular
                            • Users
                            • Groups
                            • Search
                            • Get Qt Extensions
                            • Unsolved