Results 1 to 2 of 2

Thread: How do i style a toplevel widget?

  1. #1
    Join Date
    Jan 2013
    Posts
    25
    Qt products
    Qt4
    Platforms
    Windows

    Default How do i style a toplevel widget?

    This is an issue I'm having trouble with for a long time, and usually have a workaround for, but at this time... i can no longer use my workaround.

    How do i style a top level widget

    I have a .ui file with 2 objects.:


    QWidget (MyQWidget)
    QListWidget (MyQListWidget)


    In my .css file, I just cannot style the QWidget. Say with a simple border or background. Here's what i experimented.

    Qt Code:
    1. * {border: 1px solid red}
    To copy to clipboard, switch view to plain text mode 
    Works, but obviously gives everything else a border as well

    Qt Code:
    1. QWidget {border: 1px solid red}
    To copy to clipboard, switch view to plain text mode 
    Works, but gives every QWidget a border as well

    Qt Code:
    1. #MyQWidget {border: 1px solid red}
    To copy to clipboard, switch view to plain text mode 
    Doesn't work

    Qt Code:
    1. QWidget #MyQWidget {border: 1px solid red}
    To copy to clipboard, switch view to plain text mode 
    Doesn't work

    Qt Code:
    1. QWidget > #MyQWidget {border: 1px solid red}
    To copy to clipboard, switch view to plain text mode 
    Doesn't work

    Qt Code:
    1. #MyQWidget QWidget {border: 1px solid red}
    To copy to clipboard, switch view to plain text mode 
    Doesn't work


    My usual workaround was just to add another QFrame and give it no margins. Anything below the Toplevel widget i can easily style, but not the top-widget itself.
    Can anyone please educate me how to properly style the topwidget?

  2. #2
    Join Date
    Jul 2008
    Location
    Germany
    Posts
    451
    Thanks
    9
    Thanked 59 Times in 57 Posts
    Qt products
    Qt4 Qt5
    Platforms
    Unix/X11 Windows

    Default Re: How do i style a toplevel widget?

    Quote Originally Posted by Nyte View Post
    #MyQWidget {border: 1px solid red}
    This works for me, at least with a minimal example in Designer with Qt 5.8.

    Ginsengelf

Similar Threads

  1. How to apply style for widget over application style
    By muthu-ms in forum Qt Programming
    Replies: 5
    Last Post: 21st October 2011, 09:16
  2. Replies: 10
    Last Post: 13th August 2011, 09:10
  3. How to display the button on toplevel?
    By mecland in forum Qt for Embedded and Mobile
    Replies: 0
    Last Post: 30th May 2010, 12:58
  4. style widget on canvas (qgv)
    By valtovar in forum Qt Programming
    Replies: 1
    Last Post: 30th October 2008, 01:31
  5. Toplevel widget with rounded corners.
    By munna in forum Qt Programming
    Replies: 7
    Last Post: 18th August 2006, 21:46

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.