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. QWidget setStyleSheet and text color
Forum Updated to NodeBB v4.3 + New Features

QWidget setStyleSheet and text color

Scheduled Pinned Locked Moved General and Desktop
3 Posts 2 Posters 2.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.
  • K Offline
    K Offline
    ksubox
    wrote on last edited by
    #1

    Hello,

    I try to get working veerey simple thing:
    I have class "MyTabButton : public QPushButton" and want to draw by myself with MyTabButton::paintEvent.
    I also setStyleSheet with normal & checked style:
    @
    QPushButton {
    border: 1px solid #acacac;
    background: #e1d3c7;
    background-position: top center;
    text-align: bottom center;
    color: #89827d;
    font-size: 15pt;
    font-weight: bold;
    }

    QPushButton:checked {
    background: #fe4e1c;
    color: #ffff00;
    }
    @

    But got painful problem: inside paintEvent I can't get color for checked state to draw text with:
    @style()->drawItemText(&p, lrect, Qt::AlignCenter | Qt::AlignBottom, opt.palette, true, text(), QPalette::Text);@

    I check source code - Qt use QRenderRule to draw, but this is internal class.
    How can I get colors from stylesheet in paintEvent ? Or hack somehow ?

    [edit: added missing coding tags @ SGaist]

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

      Hi,

      Style sheet and palettes are two independent beasts. However you could try to integrate the palette in the style sheet like described "here":http://doc.qt.io/qt-5/stylesheet-reference.html#paletterole

      Hope it helps

      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
      • K Offline
        K Offline
        ksubox
        wrote on last edited by
        #3

        Thank you, didn't see.
        At least will be easier to synchronise stylesheet colors & native style colors.

        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