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. QTabBar setTabText and setTabToolTip not working
QtWS25 Last Chance

QTabBar setTabText and setTabToolTip not working

Scheduled Pinned Locked Moved Solved General and Desktop
9 Posts 3 Posters 840 Views
  • 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.
  • R Offline
    R Offline
    Rory_1
    wrote on last edited by
    #1

    When I tabify QDockWidgets I want to edit the text in the QTabBar for the tabbed docks. I have set the text for one of my QDockWidgets to "F" for texting purposes. The following code extract is inside my MainWindow:

    QObjectList oList = children();
    QObject *object;
    QTabBar *tabBar = nullptr;
    foreach (object, oList) {
        if (object->metaObject()->className() == "QTabBar") {
            tabBar = qobject_cast<QTabBar *>(object);
            break;
        }
    }
    for (int i = 0; i < tabBar->count(); ++i) {
        if (tabBar->tabText(i) == "F") {
            tabBar->setTabText(i, "Folders");                           // fails
            tabBar->setTabToolTip(i, "System Folders");                 // fails
            tabBar->setTabTextColor(i, Qt::red);                        // fails
            tabBar->setTabIcon(i, QIcon(":/images/icon16/test.png"));   // works
            tabBar->setTabVisible(i, false);                            // works
        }
    }
    

    Any ideas why this if failing?

    1 Reply Last reply
    0
    • SGaistS Offline
      SGaistS Offline
      SGaist
      Lifetime Qt Champion
      wrote on last edited by
      #2

      Hi,

      What exactly it failing ?
      Are you sure you are working on the correct QTabBar ?

      Interested in AI ? www.idiap.ch
      Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

      1 Reply Last reply
      0
      • R Offline
        R Offline
        Rory_1
        wrote on last edited by
        #3

        The lines commented // fails are not working. Since the lines:

        tabBar->setTabIcon(i, QIcon(":/images/icon16/test.png"));   // works
        tabBar->setTabVisible(i, false);                            // works
        

        are working, I'm pretty confident I have the correct QTabBar. In addition, a QDebug reported the correct text, which I removed for brevity. Finally, there is only 1 QTabBar in oList.

        1 Reply Last reply
        0
        • SGaistS Offline
          SGaistS Offline
          SGaist
          Lifetime Qt Champion
          wrote on last edited by
          #4

          They are working because they are left untouched by the QMainWindow internal layout.

          See here for more details.

          Interested in AI ? www.idiap.ch
          Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

          R 1 Reply Last reply
          0
          • SGaistS SGaist

            They are working because they are left untouched by the QMainWindow internal layout.

            See here for more details.

            R Offline
            R Offline
            Rory_1
            wrote on last edited by
            #5

            @SGaist Thanks for the link. I'm not seeing how this will help me. Can you give me a hint on how to rename the tab text and set the tooltip in this situation? Much appreciated.

            1 Reply Last reply
            0
            • nageshN Offline
              nageshN Offline
              nagesh
              wrote on last edited by
              #6

              @Rory_1 said in QTabBar setTabText and setTabToolTip not working:

              tabBar->setTabVisible(i, false); // works

              visibility is set to false/hidden. Where do you verify it's text changed or not?

              R 1 Reply Last reply
              0
              • nageshN nagesh

                @Rory_1 said in QTabBar setTabText and setTabToolTip not working:

                tabBar->setTabVisible(i, false); // works

                visibility is set to false/hidden. Where do you verify it's text changed or not?

                R Offline
                R Offline
                Rory_1
                wrote on last edited by
                #7

                @nagesh I have tried all changes separately. I've just included setTabVisible to show what has worked and what has not.

                1 Reply Last reply
                0
                • SGaistS Offline
                  SGaistS Offline
                  SGaist
                  Lifetime Qt Champion
                  wrote on last edited by
                  #8

                  @Rory_1 said in QTabBar setTabText and setTabToolTip not working:

                  @SGaist Thanks for the link. I'm not seeing how this will help me. Can you give me a hint on how to rename the tab text and set the tooltip in this situation? Much appreciated.

                  That's what the code shows, you can't as the content of the tab bar is updated based on the QDockWidget, so either you modify the dock widget on docking/undocking or you can try KDDockWidgets. Last option is to build your own qtbase with the modification required to implement what you want.

                  Interested in AI ? www.idiap.ch
                  Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

                  R 1 Reply Last reply
                  0
                  • SGaistS SGaist

                    @Rory_1 said in QTabBar setTabText and setTabToolTip not working:

                    @SGaist Thanks for the link. I'm not seeing how this will help me. Can you give me a hint on how to rename the tab text and set the tooltip in this situation? Much appreciated.

                    That's what the code shows, you can't as the content of the tab bar is updated based on the QDockWidget, so either you modify the dock widget on docking/undocking or you can try KDDockWidgets. Last option is to build your own qtbase with the modification required to implement what you want.

                    R Offline
                    R Offline
                    Rory_1
                    wrote on last edited by
                    #9

                    @SGaist Thanks very much. Have a great weekend.

                    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