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. Centering a CheckBox in a GridLayout

Centering a CheckBox in a GridLayout

Scheduled Pinned Locked Moved Solved General and Desktop
8 Posts 5 Posters 761 Views
  • 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
    andi456
    wrote on last edited by
    #1

    Hi,
    maybe there's something obvious, that I am missing, but after searching the web for quite some time, I haven't been able to find an answer to this. As the title of my post suggests I want to achieve something rather simple, i.e., I'd like to have QCheckBox instance without text horizontally centered in the middle of a GridLayout.

    I found some hints regarding QStyleSheet, but couldn't find any really useful description of how to proceed to reach my goal.

    Kind regards,

    Andreas

    JoeCFDJ 1 Reply Last reply
    0
    • A andi456

      Hi,
      maybe there's something obvious, that I am missing, but after searching the web for quite some time, I haven't been able to find an answer to this. As the title of my post suggests I want to achieve something rather simple, i.e., I'd like to have QCheckBox instance without text horizontally centered in the middle of a GridLayout.

      I found some hints regarding QStyleSheet, but couldn't find any really useful description of how to proceed to reach my goal.

      Kind regards,

      Andreas

      JoeCFDJ Offline
      JoeCFDJ Offline
      JoeCFD
      wrote on last edited by
      #2

      @andi456 what have your tried? Can you show the picture of your layout?
      OS + Qt version?

      A 1 Reply Last reply
      0
      • JoeCFDJ JoeCFD

        @andi456 what have your tried? Can you show the picture of your layout?
        OS + Qt version?

        A Offline
        A Offline
        andi456
        wrote on last edited by
        #3

        @JoeCFD Well, I constructed the Layout via QtCreator and it looks like this at the moment:

        checkbox_gridLayout.png

        What does work, is, putting the checkBox field to the right, but not into the center.

        Christian EhrlicherC 1 Reply Last reply
        0
        • A andi456

          @JoeCFD Well, I constructed the Layout via QtCreator and it looks like this at the moment:

          checkbox_gridLayout.png

          What does work, is, putting the checkBox field to the right, but not into the center.

          Christian EhrlicherC Offline
          Christian EhrlicherC Offline
          Christian Ehrlicher
          Lifetime Qt Champion
          wrote on last edited by
          #4

          @andi456 Use three columns for the TextLabel, put the checkBox in the center one.

          Qt Online Installer direct download: https://download.qt.io/official_releases/online_installers/
          Visit the Qt Academy at https://academy.qt.io/catalog

          A 1 Reply Last reply
          0
          • Christian EhrlicherC Christian Ehrlicher

            @andi456 Use three columns for the TextLabel, put the checkBox in the center one.

            A Offline
            A Offline
            andi456
            wrote on last edited by
            #5

            @Christian-Ehrlicher You mean, a textlabel spanning over three columns, right? Ok, I think that will do trick.

            Anyway, I just wonder, why there's no checkbox/radiobutton without a label attached to it.

            M Pl45m4P 2 Replies Last reply
            0
            • A andi456

              @Christian-Ehrlicher You mean, a textlabel spanning over three columns, right? Ok, I think that will do trick.

              Anyway, I just wonder, why there's no checkbox/radiobutton without a label attached to it.

              M Offline
              M Offline
              mpergand
              wrote on last edited by
              #6

              @andi456
              Try right click on the checkbox -> layout alignment -> center horizontally

              1 Reply Last reply
              1
              • A andi456

                @Christian-Ehrlicher You mean, a textlabel spanning over three columns, right? Ok, I think that will do trick.

                Anyway, I just wonder, why there's no checkbox/radiobutton without a label attached to it.

                Pl45m4P Online
                Pl45m4P Online
                Pl45m4
                wrote on last edited by Pl45m4
                #7

                @andi456 said in Centering a CheckBox in a GridLayout:

                Anyway, I just wonder, why there's no checkbox/radiobutton without a label attached to it.

                Because nobody forces you to actually put text there?! :)
                If you want to center the checkBox within its own cell and not put it in the center of the whole GridLayout, what I initially thought you are trying to do, then @mpergand 's solution will do exactly this.

                The code for it would look like this:

                    gridLayout->setAlignment(yourCheckBox, Qt::AlignHCenter);
                

                If debugging is the process of removing software bugs, then programming must be the process of putting them in.

                ~E. W. Dijkstra

                A 1 Reply Last reply
                0
                • Pl45m4P Pl45m4

                  @andi456 said in Centering a CheckBox in a GridLayout:

                  Anyway, I just wonder, why there's no checkbox/radiobutton without a label attached to it.

                  Because nobody forces you to actually put text there?! :)
                  If you want to center the checkBox within its own cell and not put it in the center of the whole GridLayout, what I initially thought you are trying to do, then @mpergand 's solution will do exactly this.

                  The code for it would look like this:

                      gridLayout->setAlignment(yourCheckBox, Qt::AlignHCenter);
                  
                  A Offline
                  A Offline
                  andi456
                  wrote on last edited by
                  #8

                  @Pl45m4 Thanks, it's sometimes a little bit confusing for me working with the design features of qt-creator.

                  Will set this to solved.

                  Kind regards.

                  1 Reply Last reply
                  0
                  • A andi456 has marked this topic as solved on

                  • Login

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