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. Programatically make a tab's text bold
Forum Update on Monday, May 27th 2025

Programatically make a tab's text bold

Scheduled Pinned Locked Moved Solved General and Desktop
13 Posts 6 Posters 4.6k 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.
  • V Offline
    V Offline
    Vadi2
    wrote on 3 Apr 2018, 20:09 last edited by
    #1

    How can I programatically make a tab's text bold?

    I'm looking to notify the user that they need to look at it.

    J 1 Reply Last reply 4 Apr 2018, 05:57
    0
    • M Offline
      M Offline
      mrjj
      Lifetime Qt Champion
      wrote on 3 Apr 2018, 20:14 last edited by
      #2

      Hi
      Perhaps you could use a stylesheet and change the current tab to highlight it
      QTabBar::tab:selected. { font-weight: bold; }

      1 Reply Last reply
      0
      • V Offline
        V Offline
        Vadi2
        wrote on 3 Apr 2018, 20:41 last edited by
        #3

        I need to specifically choose which tab to make bold, and it can't be just the currently selected - it could be unselected too. Any ideas?

        M 1 Reply Last reply 3 Apr 2018, 20:56
        0
        • V Vadi2
          3 Apr 2018, 20:41

          I need to specifically choose which tab to make bold, and it can't be just the currently selected - it could be unselected too. Any ideas?

          M Offline
          M Offline
          mrjj
          Lifetime Qt Champion
          wrote on 3 Apr 2018, 20:56 last edited by
          #4

          @Vadi2
          since its random tabs, not sure you can target that with stylesheet.
          I was wondering if text color could work, so instead of Bold, then some color ?
          http://doc.qt.io/qt-5/qtabbar.html#setTabTextColor
          http://doc.qt.io/qt-5/qtabwidget.html#tabBar

          1 Reply Last reply
          0
          • V Offline
            V Offline
            Vadi2
            wrote on 3 Apr 2018, 20:57 last edited by
            #5

            A colour is different because the user could have a custom theme that conflicts. I'd really like it bold - like Firefox can and so on.

            1 Reply Last reply
            0
            • A Offline
              A Offline
              aha_1980
              Lifetime Qt Champion
              wrote on 3 Apr 2018, 20:58 last edited by
              #6

              can the tabText be HTML? this would allow any kind of formatting, including bold.

              Qt has to stay free or it will die.

              1 Reply Last reply
              1
              • V Offline
                V Offline
                Vadi2
                wrote on 4 Apr 2018, 05:09 last edited by
                #7

                I tried setTabText(i, "<b>testing</b>"); and it did not work.

                1 Reply Last reply
                0
                • V Vadi2
                  3 Apr 2018, 20:09

                  How can I programatically make a tab's text bold?

                  I'm looking to notify the user that they need to look at it.

                  J Offline
                  J Offline
                  J.Hilk
                  Moderators
                  wrote on 4 Apr 2018, 05:57 last edited by
                  #8

                  @Vadi2
                  mmh, haven't tried it, but I think, you can potentially set an Icon, that spans the whole tab width, that would give the illusion a modified Tab-Text ?

                  Edit:

                  Google search, brought me to this old forum post

                  @SGaist and @Goutye
                  had the right idea, re-implement paintEvent seems to be agood (the best?) option


                  Be aware of the Qt Code of Conduct, when posting : https://forum.qt.io/topic/113070/qt-code-of-conduct


                  Q: What's that?
                  A: It's blue light.
                  Q: What does it do?
                  A: It turns blue.

                  1 Reply Last reply
                  2
                  • A Offline
                    A Offline
                    Alain38 0
                    wrote on 4 Apr 2018, 11:17 last edited by
                    #9

                    Hi,
                    I supposed that you have a QTabWidget and just wants to change the style of one tab button. Have you tried something like:

                    myTabWigdet->tabBar()->tabButton(myIndex, 0)->setStyleSheet("MyStyle");
                    
                    1 Reply Last reply
                    0
                    • V Offline
                      V Offline
                      Vadi2
                      wrote on 4 Apr 2018, 12:09 last edited by
                      #10

                      The tab button (X) is not what I'm looking for - I want to grab the tab itself, not the close button within it :(

                      D 1 Reply Last reply 5 Apr 2018, 02:44
                      0
                      • V Vadi2
                        4 Apr 2018, 12:09

                        The tab button (X) is not what I'm looking for - I want to grab the tab itself, not the close button within it :(

                        D Offline
                        D Offline
                        Devopia53
                        wrote on 5 Apr 2018, 02:44 last edited by
                        #11

                        @Vadi2

                        Using re-implemented paintEvent() is too complicated. Rather, i think using something like QProxyStyle would be a better choice.

                        J 1 Reply Last reply 5 Apr 2018, 04:43
                        1
                        • D Devopia53
                          5 Apr 2018, 02:44

                          @Vadi2

                          Using re-implemented paintEvent() is too complicated. Rather, i think using something like QProxyStyle would be a better choice.

                          J Offline
                          J Offline
                          J.Hilk
                          Moderators
                          wrote on 5 Apr 2018, 04:43 last edited by
                          #12

                          @Devopia53 when I read my Interest-Email feed correctly, than the OP has a solution to the problem, with indeed using QProxyStyle. But hasn't updated the topic to solved yet.

                          since when is re-implemented paintEvent() to complicated? Thats about 20 lines of code to get the desired result, in this case at least.


                          Be aware of the Qt Code of Conduct, when posting : https://forum.qt.io/topic/113070/qt-code-of-conduct


                          Q: What's that?
                          A: It's blue light.
                          Q: What does it do?
                          A: It turns blue.

                          1 Reply Last reply
                          2
                          • V Offline
                            V Offline
                            Vadi2
                            wrote on 6 Apr 2018, 08:35 last edited by
                            #13

                            Yep, solved with http://lists.qt-project.org/pipermail/interest/2018-April/029734.html. Thanks everyone.

                            1 Reply Last reply
                            4

                            1/13

                            3 Apr 2018, 20:09

                            • Login

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