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. Changing app's QPushButtons' backgrounds with global stylesheet breaks its dimensions.
Forum Updated to NodeBB v4.3 + New Features

Changing app's QPushButtons' backgrounds with global stylesheet breaks its dimensions.

Scheduled Pinned Locked Moved Solved General and Desktop
10 Posts 2 Posters 743 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.
  • A Offline
    A Offline
    AlexNevskiy
    wrote on 31 May 2022, 13:35 last edited by AlexNevskiy
    #1

    Hello all!

    Imagine that I want all buttons in my prog to have a nice gradient look. And I use a global app stylesheet for this purpose. But something not understandable is going on when I'm trying to control the buttons' background through it.

    If I have buttons in horizontal layout with spacer, and set the next app stylesheet

    QPushButton {
        background: lightblue; 
        border: 1px solid blue; /* need for full overpainting */
    }
    

    then widths of all of the buttons flow away, and buttons with a little text become very small.

    If I add a line to the stylesheet:

    min-width: 80px;
    

    or, just

    width: 80px;
    

    then buttons with small text become ok, but buttons with long text not expand and their texts are partially hidden.

    So, how to change background for all buttons and not to break its dimensions?

    1 Reply Last reply
    0
    • T Offline
      T Offline
      Tink
      wrote on 31 May 2022, 14:14 last edited by
      #2

      Perhaps add some padding. E.g. padding: 5px;

      T A 2 Replies Last reply 31 May 2022, 14:50
      0
      • T Tink
        31 May 2022, 14:14

        Perhaps add some padding. E.g. padding: 5px;

        T Offline
        T Offline
        Tink
        wrote on 31 May 2022, 14:50 last edited by
        #3

        Or perhaps a large maximum width.

        A 1 Reply Last reply 31 May 2022, 14:51
        0
        • T Tink
          31 May 2022, 14:14

          Perhaps add some padding. E.g. padding: 5px;

          A Offline
          A Offline
          AlexNevskiy
          wrote on 31 May 2022, 14:50 last edited by
          #4

          @Tink I tried paddings, it didn't help me.

          1 Reply Last reply
          0
          • T Tink
            31 May 2022, 14:50

            Or perhaps a large maximum width.

            A Offline
            A Offline
            AlexNevskiy
            wrote on 31 May 2022, 14:51 last edited by AlexNevskiy
            #5

            @Tink said in Changing app's QPushButtons' backgrounds with global stylesheet breaks its dimensions.:

            Or perhaps a large maximum width.

            then all the buttons will be unnecessary large

            T 1 Reply Last reply 31 May 2022, 14:54
            0
            • A AlexNevskiy
              31 May 2022, 14:51

              @Tink said in Changing app's QPushButtons' backgrounds with global stylesheet breaks its dimensions.:

              Or perhaps a large maximum width.

              then all the buttons will be unnecessary large

              T Offline
              T Offline
              Tink
              wrote on 31 May 2022, 14:54 last edited by
              #6

              @AlexNevskiy hmm... perhaps you need to change the sizePolicy?

              A 1 Reply Last reply 31 May 2022, 14:59
              0
              • A Offline
                A Offline
                AlexNevskiy
                wrote on 31 May 2022, 14:56 last edited by
                #7

                So, I have found some sort of solution. Just need to set width of expanding spacer to minimum (0 for example). And it works some how.

                T 1 Reply Last reply 31 May 2022, 15:00
                1
                • T Tink
                  31 May 2022, 14:54

                  @AlexNevskiy hmm... perhaps you need to change the sizePolicy?

                  A Offline
                  A Offline
                  AlexNevskiy
                  wrote on 31 May 2022, 14:59 last edited by
                  #8

                  @Tink said in Changing app's QPushButtons' backgrounds with global stylesheet breaks its dimensions.:

                  @AlexNevskiy hmm... perhaps you need to change the sizePolicy?

                  Which policy will make it work?

                  T 1 Reply Last reply 31 May 2022, 15:03
                  0
                  • A AlexNevskiy
                    31 May 2022, 14:56

                    So, I have found some sort of solution. Just need to set width of expanding spacer to minimum (0 for example). And it works some how.

                    T Offline
                    T Offline
                    Tink
                    wrote on 31 May 2022, 15:00 last edited by
                    #9

                    @AlexNevskiy said in Changing app's QPushButtons' backgrounds with global stylesheet breaks its dimensions.:

                    So, I have found some sort of solution. Just need to set width of expanding spacer to minimum (0 for example). And it works some how.

                    Makes sense.

                    1 Reply Last reply
                    0
                    • A AlexNevskiy
                      31 May 2022, 14:59

                      @Tink said in Changing app's QPushButtons' backgrounds with global stylesheet breaks its dimensions.:

                      @AlexNevskiy hmm... perhaps you need to change the sizePolicy?

                      Which policy will make it work?

                      T Offline
                      T Offline
                      Tink
                      wrote on 31 May 2022, 15:03 last edited by
                      #10

                      @AlexNevskiy said in Changing app's QPushButtons' backgrounds with global stylesheet breaks its dimensions.:

                      @Tink said in Changing app's QPushButtons' backgrounds with global stylesheet breaks its dimensions.:

                      @AlexNevskiy hmm... perhaps you need to change the sizePolicy?

                      Which policy will make it work?

                      Well i have most of my widgets on preferred since i dont understand the effects well enough:)
                      But if you add a pushbutton in designer it has horizontal: minimum.

                      1 Reply Last reply
                      0

                      7/10

                      31 May 2022, 14:56

                      • Login

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