Results 1 to 7 of 7

Thread: QPalette::brush

Hybrid View

Previous Post Previous Post   Next Post Next Post
  1. #1
    Join Date
    May 2006
    Location
    Bangalore,India
    Posts
    235
    Qt products
    Qt3 Qt4
    Platforms
    Windows
    Thanks
    7
    Thanked 25 Times in 24 Posts

    Default Re: QPalette::brush

    use the following:
    Qt Code:
    1. setBackgroundRole( QPalette::AlternateBase);
    2. setBackgroundRole( QPalette::Base);
    3.  
    4. OR
    5.  
    6. QPalette palette;
    7. palette.setColor(m_tabel->backgroundRole(), Qt::transparent); // any Qt::color
    8. m_tabel->setPalette(palette);
    To copy to clipboard, switch view to plain text mode 

  2. #2
    Join Date
    Oct 2006
    Location
    Hawaii
    Posts
    130
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows
    Thanks
    48
    Thanked 4 Times in 4 Posts

    Default Re: QPalette::brush

    perhaps i didn't explain well enough what I am doing. I am coloring the rows in a QTableWidget in alternating colors, but 2 rows 1 color, then 2 rows the other. The only way I have found so far was to color the cells as I generate the rows:

    Qt Code:
    1. ui.tablewidget->item(0, 3)->setBackground(highlightBrush);
    2. ui.tablewidget->item(0, 4)->setBackground(highlightBrush);
    3. //etc...
    To copy to clipboard, switch view to plain text mode 
    This works, however it does not completely match the base and alternate base color (because I don't know how to construct brushes that take from those colors)

    The background role method:
    Qt Code:
    1. //this produces errors as a qtablewidgetitem does not have setBackgroundRole()
    2. ui.tableWidget->item(0, 1)->setBackgroundRole(QPalette::AlternateBase);
    3. ui.tableWidget->item(0, 2)->setBackgroundRole(QPalette::Base);
    To copy to clipboard, switch view to plain text mode 
    Will not work because QTableWidgetItem does not accept setBackgroundRole, it only accepts a brush in setBackground()

    so all I need to know really, is how to create a brush from the color used in QPalette::AlternateBase and QPalette::Base or use the existing brush for those colors (but how to reference it I have no clue.

  3. #3
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    5,372
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11 Windows
    Thanks
    28
    Thanked 976 Times in 912 Posts

    Default Re: QPalette::brush

    Quote Originally Posted by tpf80 View Post
    so all I need to know really, is how to create a brush from the color used in QPalette::AlternateBase and QPalette::Base
    Ask QPalette to give you one.

  4. #4
    Join Date
    Oct 2006
    Location
    Hawaii
    Posts
    130
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows
    Thanks
    48
    Thanked 4 Times in 4 Posts

    Default Re: QPalette::brush

    I actually tried this (see above) but I got errors. (this was the way I really wanted to do it)
    Qt Code:
    1. tableNoHighlight = QPalette::brush(QPalette::AlternateBase);
    2. tableNoHighlight = QPalette::brush(QPalette::Base);
    To copy to clipboard, switch view to plain text mode 
    it asks for an object, but I am not quite sure what object its asking for.

  5. #5
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    5,372
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11 Windows
    Thanks
    28
    Thanked 976 Times in 912 Posts

    Default Re: QPalette::brush

    Quote Originally Posted by tpf80 View Post
    it asks for an object, but I am not quite sure what object its asking for.
    QPalette::brush() isn't a static method, so you have to create a QPalette object first:
    Qt Code:
    1. tableNoHighlight = p.brush(QPalette::Base);
    To copy to clipboard, switch view to plain text mode 

  6. The following user says thank you to jacek for this useful post:

    tpf80 (18th July 2007)

  7. #6
    Join Date
    Oct 2006
    Location
    Hawaii
    Posts
    130
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows
    Thanks
    48
    Thanked 4 Times in 4 Posts

    Smile Re: QPalette::brush

    ah I see.. I knew it was something simple that I was missing...

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
  •  
Qt is a trademark of The Qt Company.