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. QGroupBox title with two different colors (left half black, right half orange)
Forum Update on Monday, May 27th 2025

QGroupBox title with two different colors (left half black, right half orange)

Scheduled Pinned Locked Moved Solved General and Desktop
qgroupboxcolor
4 Posts 3 Posters 1.2k 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.
  • MasterBLBM Offline
    MasterBLBM Offline
    MasterBLB
    wrote on last edited by
    #1

    He fellow Qt devs,

    How can I get the mentioned effect? To obtain a single title color is easy, either use palette-window text, or a style sheet...but I need two colors. Any hints?

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

      hi
      I don't think you can make it do so with a stylesheet.

      You most likely have to make your own custom GroupBox and paint it like that.

      You might also be able via a QProxyStyle with an override for
      drawItemText

      as QGroupBox uses that for the text
      proxy()->drawItemText(p, textRect, Qt::TextShowMnemonic | Qt::AlignHCenter | alignment,
      groupBox->palette, groupBox->state & State_Enabled, groupBox->text,
      textColor.isValid() ? QPalette::NoRole : QPalette::WindowText);
      as seen here
      https://code.woboq.org/qt5/qtbase/src/widgets/styles/qcommonstyle.cpp.html#3787

      1 Reply Last reply
      5
      • MasterBLBM Offline
        MasterBLBM Offline
        MasterBLB
        wrote on last edited by MasterBLB
        #3

        I reimplemented whole MyGroupBox::paintEvent() copying the drawing code from CommonStyle into it, and using drawItemText twice. Anyway, thanks mate for correct hint!
        WTF, why I can't mark @mrjj 's post as correct answer??

        J.HilkJ 1 Reply Last reply
        2
        • MasterBLBM MasterBLB

          I reimplemented whole MyGroupBox::paintEvent() copying the drawing code from CommonStyle into it, and using drawItemText twice. Anyway, thanks mate for correct hint!
          WTF, why I can't mark @mrjj 's post as correct answer??

          J.HilkJ Offline
          J.HilkJ Offline
          J.Hilk
          Moderators
          wrote on last edited by
          #4

          @MasterBLB said in QGroupBox title with two different colors (left half black, right half orange):

          WTF, why I can't mark @mrjj 's post as correct answer??

          Sadly, until we update to a newer version of the forum software, that option is not available for every user.

          I'll set it as the correct answer for you.


          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
          1

          • Login

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