Results 1 to 5 of 5

Thread: Impossible to get correct widget background color

  1. #1
    Join Date
    Oct 2008
    Location
    Brasil - São Paulo - Marília
    Posts
    28
    Thanks
    3
    Thanked 1 Time in 1 Post
    Qt products
    Qt4 Qt5
    Platforms
    Unix/X11 Windows
    Wiki edits
    3

    Question Impossible to get correct widget background color

    Hi all.

    Here is what I want to do:
    1) In paintEvent a make some draws and text in the widget using a QPainter object

    2) Then a want to give it a perfurated effect. I'm thinking in this solution

    Qt Code:
    1. QBrush brush(this->palette().background().color(),Qt::Dense4Pattern);
    2. painter.fillRect(0, 0, this->width() - 1, this->height() - 1, brush);
    To copy to clipboard, switch view to plain text mode 

    The problem is the that palette().background().color() doesn't return the right widget backgroung color. It returns an aproximate light color.

    Am I missing something?

  2. #2
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,360
    Thanks
    3
    Thanked 5,015 Times in 4,792 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: Impossible to get correct widget background color

    What is the widget? Maybe you should use base() instead of background()?
    Your biological and technological distinctiveness will be added to our own. Resistance is futile.

    Please ask Qt related questions on the forum and not using private messages or visitor messages.


  3. #3
    Join Date
    Oct 2008
    Location
    Brasil - São Paulo - Marília
    Posts
    28
    Thanks
    3
    Thanked 1 Time in 1 Post
    Qt products
    Qt4 Qt5
    Platforms
    Unix/X11 Windows
    Wiki edits
    3

    Default Re: Impossible to get correct widget background color

    I tryed base() too with no success.

    My widget is a sub-class of QPushButton, like this:
    Qt Code:
    1. class QIscButton: public QPushButton
    To copy to clipboard, switch view to plain text mode 

    I don't know if it's relevante but I'm using Slackware 12.2, with KDE 4.2.3 and the Qt version is 4.5.1.

    Thanks.
    Last edited by croscato; 8th June 2009 at 17:40.

  4. #4
    Join Date
    Oct 2008
    Location
    Brasil - São Paulo - Marília
    Posts
    28
    Thanks
    3
    Thanked 1 Time in 1 Post
    Qt products
    Qt4 Qt5
    Platforms
    Unix/X11 Windows
    Wiki edits
    3

    Default Re: Impossible to get correct widget background color

    I think I know what the problem is. Looking more carefully at the widgets background in my system I could see that In KDE using the Oxygen theme the widgets background aren't a solid color but a gradient. With colors that are close to each other, what makes the gradient almost imperceptible.

    Now my question is. How can a manage to get a QGradient that matches the KDE theme (Oxygen) without hard-code with?

    Thanks.

  5. #5
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,360
    Thanks
    3
    Thanked 5,015 Times in 4,792 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: Impossible to get correct widget background color

    Quote Originally Posted by croscato View Post
    How can a manage to get a QGradient that matches the KDE theme (Oxygen) without hard-code with?
    You can try the button() role of the palette. But I can't guarantee this will work. Otherwise you have to use QStyle API.
    Your biological and technological distinctiveness will be added to our own. Resistance is futile.

    Please ask Qt related questions on the forum and not using private messages or visitor messages.


Similar Threads

  1. button background color when it is clicked
    By navi1084 in forum Qt Programming
    Replies: 5
    Last Post: 24th June 2024, 12:09
  2. Replies: 5
    Last Post: 30th March 2008, 16:53
  3. Graphics widget with background
    By ad5xj in forum Newbie
    Replies: 2
    Last Post: 24th August 2007, 16:29
  4. transparent background of the main widget
    By nagpalma in forum Qt Programming
    Replies: 2
    Last Post: 4th May 2007, 17:52
  5. QLabel background color
    By munna in forum Newbie
    Replies: 3
    Last Post: 1st May 2006, 15:36

Tags for this Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Digia, Qt and their respective logos are trademarks of Digia Plc in Finland and/or other countries worldwide.