Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. QWidgets Stylesheets
Forum Updated to NodeBB v4.3 + New Features

QWidgets Stylesheets

Scheduled Pinned Locked Moved General and Desktop
5 Posts 4 Posters 965 Views 2 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • N Offline
    N Offline
    nefarious
    wrote on last edited by
    #1

    I am fairly new to QT and am working to see if I can figure out how to build a Qt application.

    I am having real trouble with stylesheets, attempting to set them programmaticly. I have tried setting them in the Instantiation method, setting them from the class that instantiates the class and from the main application.

        setStyleSheet("border-width: 2px; border-color: Red;");
    

    I know they are being read because if I change border to barder I get 4 messages that the style sheet can't be parsed. Is there something else I have to set to get them to work, or is there a correct place that then need to be set at? Telling me what to go read would be sufficient. I have googled this and so far, none of the suggestions seem to work.

    1 Reply Last reply
    0
    • mrjjM Offline
      mrjjM Offline
      mrjj
      Lifetime Qt Champion
      wrote on last edited by
      #2

      Hi
      If you start creator, make default new Widget Desktop project,
      Add a widget to the design area and right click it. There is Change stylesheet which is
      an editor. there you can test if syntax is valid.

      1 Reply Last reply
      1
      • N Offline
        N Offline
        nefarious
        wrote on last edited by
        #3

        What if I don't use the design area, I want to do it all programatically?

        1 Reply Last reply
        0
        • EatonCodeE Offline
          EatonCodeE Offline
          EatonCode
          wrote on last edited by
          #4

          said in QWidgets Stylesheets:

          border-width: 2px; border-color: Red;

          Try Giving it a Border Style... Right now your giving it a width and color but no style to apply it to..

          http://www.eatoncode.com/resources/shareit/Screencast_17-18_20-11-2016.mp4

          http://doc.qt.io/qt-5.7/stylesheet-examples.html

          http://www.w3schools.com/css/css_border.asp

          http://www.w3schools.com/css/tryit.asp?filename=trycss_border-style

          Hope that helps.

          1 Reply Last reply
          1
          • Chris KawaC Offline
            Chris KawaC Offline
            Chris Kawa
            Lifetime Qt Champion
            wrote on last edited by Chris Kawa
            #5

            setStyleSheet() is a method on a widget and stylesheets are cascading, meaning they work on the widget you set them on and any children it has.
            For example:

            QWidget* foo = new QWidget();
            QWidget* bar = new QWidget(foo); //child of foo
            
            foo->setStyleSheet("border: 2px solid red"); //applies to both foo and bar
            bar->setStyleSheet("background-color: blue"); //applies only to bar
            

            You can set a stylesheet from wherever you have access to the setStyleSheet() method. From the constructor, any method or from outside the class. There are no restrictions to it.

            1 Reply Last reply
            1

            • Login

            • Login or register to search.
            • First post
              Last post
            0
            • Categories
            • Recent
            • Tags
            • Popular
            • Users
            • Groups
            • Search
            • Get Qt Extensions
            • Unsolved