Results 1 to 4 of 4

Thread: Style Sheet for custom widget

  1. #1
    Join Date
    Nov 2008
    Posts
    17
    Thanks
    4
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Cool Style Sheet for custom widget

    Hi all,

    I made my custom widget based on QWidget, just several button and labels. How to set style sheet from my custom widget?

    I set object name for widget
    Qt Code:
    1. myWidget->setObjectName("myWidget");
    To copy to clipboard, switch view to plain text mode 

    and wrote small style sheet
    Qt Code:
    1. QWidget#myWidget {
    2. color: red;
    3. }
    To copy to clipboard, switch view to plain text mode 
    but nothing happened.

    The reason why I want to do it this way is because I want to have something like this in the future:

    Qt Code:
    1. QWidget#myWidget > QPushButton {
    2. color: red;
    3. }
    To copy to clipboard, switch view to plain text mode 

  2. #2
    Join Date
    Jan 2006
    Location
    Germany
    Posts
    4,380
    Thanks
    19
    Thanked 1,005 Times in 913 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows Symbian S60
    Wiki edits
    5

    Default Re: Style Sheet for custom widget

    Oh, I had this problem time ago myself, but I can't remember exactly the solution (and even find it now...) But you must either set autofillbackground or even provide a paintEvent() in your subclassed widget...

    Qt Code:
    1. MyWidget::paintEvent(QPaintEvent *e)
    2. {
    3. QWidget::paintEvent(e);
    4. }
    To copy to clipboard, switch view to plain text mode 

  3. The following user says thank you to Lykurg for this useful post:

    1111 (24th March 2009)

  4. #3
    Join Date
    Nov 2008
    Posts
    17
    Thanks
    4
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Thumbs up Re: Style Sheet for custom widget

    Thanks mate! It helps!

    Quote Originally Posted by Lykurg View Post
    Oh, I had this problem time ago myself, but I can't remember exactly the solution (and even find it now...) But you must either set autofillbackground or even provide a paintEvent() in your subclassed widget...

    Qt Code:
    1. MyWidget::paintEvent(QPaintEvent *e)
    2. {
    3. QWidget::paintEvent(e);
    4. }
    To copy to clipboard, switch view to plain text mode 

  5. #4
    Join Date
    Aug 2010
    Posts
    2
    Qt products
    Qt4
    Platforms
    MacOS X Windows

    Default Re: Style Sheet for custom widget

    Could you please provide some snippets of your code? I have the same problem and the solution doesn't work for me.
    I have Qt 4.6 btw

Similar Threads

  1. style widget on canvas (qgv)
    By valtovar in forum Qt Programming
    Replies: 1
    Last Post: 30th October 2008, 00:31
  2. QMenu style sheet: works in dev env, breaks in release
    By JimDaniel in forum Qt Programming
    Replies: 1
    Last Post: 6th October 2008, 19:18
  3. style sheet issue.
    By kaushal_gaurav in forum Qt Programming
    Replies: 2
    Last Post: 7th August 2008, 07:18
  4. QToolButton and Style sheet
    By desch in forum Qt Programming
    Replies: 8
    Last Post: 1st December 2007, 08:38
  5. Qt 4.3 Style sheet, new features
    By Angelo Moriconi in forum Qt Programming
    Replies: 2
    Last Post: 12th June 2007, 15:22

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.