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. Problem with QCheckBox

Problem with QCheckBox

Scheduled Pinned Locked Moved Unsolved General and Desktop
8 Posts 3 Posters 1.7k Views 3 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.
  • Z Offline
    Z Offline
    Zunneh
    wrote on last edited by
    #1

    Hi guys, i'm working in a project and i find a problem with the widget QCheckBox
    i want to setStyleSheet in the QCheckBox ( color ) and in the same time i want to allign my check in center, but the problem is i can't do this 2 options in the same time ?

      QCheckBox *check=new QCheckBox(this);	
      check->setStyleSheet("QWidget {background-color:#0000FF;color:white;}");
      check->setStyleSheet("margin-left:50%; margin-right:50%;}");
    

    this 2 option does not work together, i tried

         check->setStyleSheet("QWidget {background-color:#0000FF;color:white;margin-left:50%;margin-right:50%;}");
    

    and it didn't work also, can someone help me please ? thanks

    my english is average, please use simple words and try to be the most explicit, thank you

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

      hi
      Seems to work fine for me with
      check->setStyleSheet("QWidget {background-color:#0000FF;color:white;margin-left:50%;margin-right:50%;}");

      alt text

      What are you seeing since you say its not working?

      Z 1 Reply Last reply
      1
      • mrjjM mrjj

        hi
        Seems to work fine for me with
        check->setStyleSheet("QWidget {background-color:#0000FF;color:white;margin-left:50%;margin-right:50%;}");

        alt text

        What are you seeing since you say its not working?

        Z Offline
        Z Offline
        Zunneh
        wrote on last edited by
        #3

        @mrjj the QCheckBox is not in the center, only the color work, this is my problem

        my english is average, please use simple words and try to be the most explicit, thank you

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

          Hi
          but

          check->setStyleSheet("margin-left:50%; margin-right:50%;}");

          alone do net center checkmark anyway ?

          So is Question how to center checkbox with stylesheet ?

          Z 1 Reply Last reply
          2
          • mrjjM mrjj

            Hi
            but

            check->setStyleSheet("margin-left:50%; margin-right:50%;}");

            alone do net center checkmark anyway ?

            So is Question how to center checkbox with stylesheet ?

            Z Offline
            Z Offline
            Zunneh
            wrote on last edited by Zunneh
            #5

            yeah, i tried to set only color alone , it works

            setStyleSheet("QWidget {background-color:#0000FF;color:white};
            

            i tried to set in the center alone , it works

            setStyleSheet("margin-left:50%; margin-right:50%;}");
            

            but when i tried the two options in the same time, only one works (the color) in your exemple
            So my is Question how to center checkbox with stylesheet

            my english is average, please use simple words and try to be the most explicit, thank you

            Gojir4G 1 Reply Last reply
            0
            • Z Zunneh

              yeah, i tried to set only color alone , it works

              setStyleSheet("QWidget {background-color:#0000FF;color:white};
              

              i tried to set in the center alone , it works

              setStyleSheet("margin-left:50%; margin-right:50%;}");
              

              but when i tried the two options in the same time, only one works (the color) in your exemple
              So my is Question how to center checkbox with stylesheet

              Gojir4G Offline
              Gojir4G Offline
              Gojir4
              wrote on last edited by Gojir4
              #6

              @Zunneh Hi,

              50%doesn't work in stylesheet (except in specific case) so it takes it as 50px.
              Note also that background is hidden by the margins.

              @mrjj You could upvote yourslef because you gave me the right way to look https://forum.qt.io/topic/90556/unexpected-behavior-using-percentage-in-stylesheet/2 :)

              Z 1 Reply Last reply
              2
              • Gojir4G Gojir4

                @Zunneh Hi,

                50%doesn't work in stylesheet (except in specific case) so it takes it as 50px.
                Note also that background is hidden by the margins.

                @mrjj You could upvote yourslef because you gave me the right way to look https://forum.qt.io/topic/90556/unexpected-behavior-using-percentage-in-stylesheet/2 :)

                Z Offline
                Z Offline
                Zunneh
                wrote on last edited by
                #7

                @Gojir4 so do you have solution for me ?

                my english is average, please use simple words and try to be the most explicit, thank you

                Gojir4G 1 Reply Last reply
                0
                • Z Zunneh

                  @Gojir4 so do you have solution for me ?

                  Gojir4G Offline
                  Gojir4G Offline
                  Gojir4
                  wrote on last edited by
                  #8

                  @Zunneh Actually the only solution I have in mind is wrapping combo box in a widget with blue background, and center the combo box inside the widget using spacer items

                  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