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. [Solved] How to override a child QWidget's background colour?

[Solved] How to override a child QWidget's background colour?

Scheduled Pinned Locked Moved General and Desktop
2 Posts 1 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.
  • JKSHJ Offline
    JKSHJ Offline
    JKSH
    Moderators
    wrote on last edited by
    #1

    Hi all,

    I'm trying to make my QLCDNumber change its background colour according to its value.
    @
    void ParentWidget::updateLcd(int value)
    {
    QPalette p;

    if (value > 10)
        p.setColor(QPalette::Window, QColor("red"));
    else
        p.setColor(QPalette::Window, QColor("green"));
    
    childLcd->setPalette(p);
    childLcd->display(value);
    

    }
    @

    This works if the QLCDNumber is created as a top-level widget, but not if it's made a child of ParentWidget -- it seems to be forced to use its parent's palette.

    What options do I have?

    I've also tried childLcd->setPalette(Qt::red) -- that does work, but it only colours the borders, not the whole background.

    Qt Doc Search for browsers: forum.qt.io/topic/35616/web-browser-extension-for-improved-doc-searches

    1 Reply Last reply
    0
    • JKSHJ Offline
      JKSHJ Offline
      JKSH
      Moderators
      wrote on last edited by
      #2

      Ah, apparently I need to call
      @
      childLcd->setAutoFillBackground(true)
      @

      Works now!

      Qt Doc Search for browsers: forum.qt.io/topic/35616/web-browser-extension-for-improved-doc-searches

      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