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)
QtWS25 Last Chance

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.
  • M Offline
    M Offline
    MasterBLB
    wrote on 28 Apr 2019, 11:08 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
    • M Offline
      M Offline
      mrjj
      Lifetime Qt Champion
      wrote on 28 Apr 2019, 11:22 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
      • M Offline
        M Offline
        MasterBLB
        wrote on 29 Apr 2019, 07:53 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 1 Reply Last reply 29 Apr 2019, 08:52
        2
        • M MasterBLB
          29 Apr 2019, 07:53

          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 Offline
          J Offline
          J.Hilk
          Moderators
          wrote on 29 Apr 2019, 08:52 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

          3/4

          29 Apr 2019, 07:53

          • Login

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