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

Set color of QWidget

Scheduled Pinned Locked Moved General and Desktop
4 Posts 2 Posters 22.7k 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.
  • R Offline
    R Offline
    Ruzik
    wrote on 21 Jun 2011, 19:41 last edited by
    #1

    Hellow, i have one problem:
    I need to set color of QWidget, how can i do it without QSS
    I try
    @ QPalette * p = new QPalette;
    p->setColor(QPalette::Window, Qt::red);
    w->setPalette(*p);@
    @ QPalette * p = new QPalette;
    p->setColor(QPalette::Background, Qt::red);
    w->setPalette(*p);@
    @ QPalette * p = new QPalette;
    p->setColor(w->foregroundRole() , Qt::red);
    w->setPalette(*p);@
    @ QPalette * p = new QPalette;
    p->setColor(w->backgroundRole() , Qt::red);
    w->setPalette(*p);@
    w is a object of QWidget
    But it is all doesnt work

    1 Reply Last reply
    0
    • L Offline
      L Offline
      leon.anavi
      wrote on 21 Jun 2011, 19:47 last edited by
      #2

      Instead you can try to do it using stylesheets. It should be something like this:
      @
      w->setStyleSheet("background-color:red;");
      @

      Edit: Sorry I saw that you do not want to use QSS too late.

      @
      QPalette p(palette());
      p.setColor(QPalette::Background, Qt::red);
      w->setAutoFillBackground(true);
      w->setPalette(p);
      @

      For more details please check "this article":http://developer.qt.nokia.com/wiki/How_to_Change_the_Background_Color_of_QWidget

      http://anavi.org/

      1 Reply Last reply
      1
      • R Offline
        R Offline
        Ruzik
        wrote on 21 Jun 2011, 19:59 last edited by
        #3

        Many thanks for your help

        1 Reply Last reply
        0
        • L Offline
          L Offline
          leon.anavi
          wrote on 21 Jun 2011, 20:12 last edited by
          #4

          You are welcome! Sorry again for my first proposition - I rushed to answer without having read the question carefully :)

          http://anavi.org/

          1 Reply Last reply
          0

          1/4

          21 Jun 2011, 19:41

          • Login

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