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

Centering a CheckBox in a GridLayout

Scheduled Pinned Locked Moved Solved General and Desktop
8 Posts 5 Posters 814 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
    andi456
    wrote on 24 Jan 2024, 10:49 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

    J 1 Reply Last reply 24 Jan 2024, 15:49
    0
    • A andi456
      24 Jan 2024, 10:49

      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

      J Offline
      J Offline
      JoeCFD
      wrote on 24 Jan 2024, 15:49 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 24 Jan 2024, 18:11
      0
      • J JoeCFD
        24 Jan 2024, 15:49

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

        A Offline
        A Offline
        andi456
        wrote on 24 Jan 2024, 18:11 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.

        C 1 Reply Last reply 24 Jan 2024, 18:26
        0
        • A andi456
          24 Jan 2024, 18:11

          @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.

          C Offline
          C Offline
          Christian Ehrlicher
          Lifetime Qt Champion
          wrote on 24 Jan 2024, 18:26 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 24 Jan 2024, 18:52
          0
          • C Christian Ehrlicher
            24 Jan 2024, 18:26

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

            A Offline
            A Offline
            andi456
            wrote on 24 Jan 2024, 18:52 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 P 2 Replies Last reply 24 Jan 2024, 19:56
            0
            • A andi456
              24 Jan 2024, 18:52

              @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 24 Jan 2024, 19:56 last edited by
              #6

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

              1 Reply Last reply
              1
              • A andi456
                24 Jan 2024, 18:52

                @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.

                P Offline
                P Offline
                Pl45m4
                wrote on 24 Jan 2024, 23:27 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 6 Feb 2024, 14:31
                0
                • P Pl45m4
                  24 Jan 2024, 23:27

                  @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 6 Feb 2024, 14:31 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 6 Feb 2024, 14:31

                  • Login

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