Results 1 to 4 of 4

Thread: styling parent but not child?

  1. #1
    Join Date
    Jun 2011
    Posts
    56
    Thanks
    7
    Qt products
    Qt4

    Default styling parent but not child?

    Is it possible to style the parent of a widget, but prevent child widgets from inheriting the parent's style?

    Say I have a QListView, which can have 2 scrollbars. If I set the background style of the QListView to say, background:red, the scrollbars will likewise color red, but I'd like them to assume the system default color.

  2. #2
    Join Date
    Jun 2011
    Posts
    56
    Thanks
    7
    Qt products
    Qt4

    Default Re: styling parent but not child?

    My current solution is this:

    - setAttribute(Qt::WA_NoSystemBackground) on the view,
    - override view's paintEvent() and repaint the background manually, but differently for the "main" area and the areas of the scrollbars, if they are visible.

  3. #3
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,359
    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: styling parent but not child?

    Quote Originally Posted by ugluk View Post
    Say I have a QListView, which can have 2 scrollbars. If I set the background style of the QListView to say, background:red, the scrollbars will likewise color red, but I'd like them to assume the system default color.
    Qt Code:
    1. QPalette p = view->palette();
    2. p.setColor(QPalette::Base, Qt::red);
    3. view->setPalette(p);
    To copy to clipboard, switch view to plain text mode 
    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.


  4. The following user says thank you to wysota for this useful post:

    ugluk (13th October 2011)

  5. #4
    Join Date
    Jun 2011
    Posts
    56
    Thanks
    7
    Qt products
    Qt4

    Default Re: styling parent but not child?

    It works! Thanks!

Similar Threads

  1. Parent-child realtionship
    By AviMittal in forum Qt Programming
    Replies: 3
    Last Post: 25th June 2009, 15:44
  2. parent/child callback
    By mhoover in forum General Programming
    Replies: 2
    Last Post: 24th June 2009, 23:50
  3. Parent window over child
    By neolol in forum Qt Programming
    Replies: 4
    Last Post: 15th May 2009, 21:15
  4. Child-Parent Widget??
    By anupamgee in forum Qt Programming
    Replies: 1
    Last Post: 11th May 2009, 13:17
  5. Parent-child-problems ;)
    By nupul in forum Qt Programming
    Replies: 11
    Last Post: 9th May 2006, 14:03

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.