Qt Forum

    • Login
    • Search
    • Categories
    • Recent
    • Tags
    • Popular
    • Users
    • Groups
    • Search
    • Unsolved

    Qt Academy Launch in California!

    QWidgets Stylesheets

    General and Desktop
    4
    5
    671
    Loading More Posts
    • 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
      nefarious last edited by

      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 Reply Quote 0
      • mrjj
        mrjj Lifetime Qt Champion last edited by

        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 Reply Quote 1
        • N
          nefarious last edited by

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

          1 Reply Last reply Reply Quote 0
          • EatonCode
            EatonCode last edited by

            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 Reply Quote 1
            • Chris Kawa
              Chris Kawa Moderators last edited by Chris Kawa

              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 Reply Quote 1
              • First post
                Last post