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. Qt Designer - Global Stylesheet
Forum Updated to NodeBB v4.3 + New Features

Qt Designer - Global Stylesheet

Scheduled Pinned Locked Moved General and Desktop
8 Posts 3 Posters 6.0k 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.
  • U Offline
    U Offline
    uruloke
    wrote on last edited by uruloke
    #1

    Hello, I have created an app and I read several places that Qt Designer supports global stylesheets instead of making the stylesheet on each object.
    My problem is that I cannot get this to work.
    For example if i call a QPushButton that is inside a QFrame, it doesn't add the styling.
    QFrame{ border: 0px solid black; border-radius: 10px; background: rgb(127, 127, 127); } QPushButton{ top: 200px; background: pink; }
    The biggest reason I would like this to work, is because else I am not able to create my program like I want it. I want to when I hover a button, that another button changes color.
    Like this:
    QPushButton#Achievement:hover + QPushButton#Achievement2{ background: rgb(232, 232, 232); color: rgb(104, 104, 104); }

    But this clearly doesn't work too, as I cannot call any other objects inside the stylesheets for a specific object.

    So where do I find the global stylesheet so I can make the above hover work?

    1 Reply Last reply
    0
    • sierdzioS Offline
      sierdzioS Offline
      sierdzio
      Moderators
      wrote on last edited by
      #2

      You can set the stylesheet for the whole application like using setStyleSheet().

      If you set the style sheet for one widget, it will be automatically applied to all it's children.

      (Z(:^

      U 1 Reply Last reply
      0
      • sierdzioS sierdzio

        You can set the stylesheet for the whole application like using setStyleSheet().

        If you set the style sheet for one widget, it will be automatically applied to all it's children.

        U Offline
        U Offline
        uruloke
        wrote on last edited by
        #3

        @sierdzio
        As the title said, this is with QT Designer,
        How do i call the setStyleSheet within QT Designer?

        M 1 Reply Last reply
        0
        • sierdzioS Offline
          sierdzioS Offline
          sierdzio
          Moderators
          wrote on last edited by
          #4

          @uruloke said:

          How do i call the setStyleSheet within QT Designer?

          You can't, as far as I am aware. But your code will later be used in an application, right? And there you can set the stylesheet using setStyleSheet().

          (Z(:^

          U 1 Reply Last reply
          0
          • sierdzioS sierdzio

            @uruloke said:

            How do i call the setStyleSheet within QT Designer?

            You can't, as far as I am aware. But your code will later be used in an application, right? And there you can set the stylesheet using setStyleSheet().

            U Offline
            U Offline
            uruloke
            wrote on last edited by
            #5

            @sierdzio
            Well yes ofc, It will later be used with Python.
            Just annoying to test my code out if I cannot do all the things in one place...

            But how do I use the set StyleSheet() with python? just to be sure how to use it correctly.

            1 Reply Last reply
            0
            • sierdzioS Offline
              sierdzioS Offline
              sierdzio
              Moderators
              wrote on last edited by
              #6

              I think the API for PyQt and other ports is the same as for Qt itself. Just check out the documentation for QWidget's setStyleSheet() and QApplication's setStyleSheet()

              (Z(:^

              U 1 Reply Last reply
              0
              • sierdzioS sierdzio

                I think the API for PyQt and other ports is the same as for Qt itself. Just check out the documentation for QWidget's setStyleSheet() and QApplication's setStyleSheet()

                U Offline
                U Offline
                uruloke
                wrote on last edited by
                #7

                @sierdzio
                Thank you, that acutally works.
                Now I just have to port my whole program into python instead of in Pyqt designer...

                1 Reply Last reply
                0
                • U uruloke

                  @sierdzio
                  As the title said, this is with QT Designer,
                  How do i call the setStyleSheet within QT Designer?

                  M Offline
                  M Offline
                  maximus
                  wrote on last edited by
                  #8

                  @uruloke

                  hey there,
                  you can create a "dummy" widget in Designer, add stylesheet to it in designer, then use this widget stylesheet in the code like this to have a clean 1 line setStyleSheet()

                  // App Stylesheet (hack so I can type stylesheet in designer instead of source code)
                  Z_StyleSheet styleSheetDummy;
                  app.setStyleSheet(styleSheetDummy.styleSheet());
                  

                  Free Indoor Cycling Software - https://maximumtrainer.com

                  1 Reply Last reply
                  0

                  • Login

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