Important: Please read the Qt Code of Conduct -

Changing alignment of check boxes within QGrid

  • Hello all,

    I currently have a QGridLayout with checkboxes and labels. I am able to get the label horizontally aligned in the center. However, the alignment for my checkboxes and labels are off since the checkboxes are currently aligned to the left.

    I have been searching but haven't found anything yet, is there any way that I can make the checkboxes align to the center so that the checkboxes are aligned with my labels which are horizontally centered?

    Thank you

  • Lifetime Qt Champion

    @Omni_Philm When using to add items you can specify alignment - did you?

  • @jsulm Thank you for your reply. I apologie that I did not mention this in my original posting. I am using the designer and I do not see that option. However, that is good to know in the future!

    Looking through the documentation, there is a setAlignment function for the QLayout class. I am assuming that I need to pass a pointer to the QWidget that I want to align to? I am looking at this function:

    Is there a faster way of doing the two step process? If I have like 20 checkboxes in the layout, this can be quite tedious.

  • Lifetime Qt Champion

    You mean like this ?
    alt text

    alt text

  • @mrjj

    Aw man, you have got to be kidding me!!!! It was there the entire time!!! I feel silly now!

    Oh well, I learned a new command for the designer.

    Thank you so much, my alignment issues are now a thing of the past!

  • Lifetime Qt Champion

    Dont worry, its pretty normal.
    I think i used Designer for maybe 8 months before i discovered that i could actually insert splitter in Designer :)
    alt text
    The option is only shown if u have selected 2+ widgets.

    Or the secret Refactor menu in Creator code editor.
    alt text
    Allowing very easy to insert a virtual function from the base class by simply selecting in the list.
    Or that it can add the function body to the cpp. (or reverse)
    Or the odd little light bulb
    alt text
    when i changed the function parameters, which turned out to be a super feature
    alt text
    that allows you to have Creator change the .h file or reverse so they match. (again)
    And finally after right click alot , i found out that alt+enter triggers the menu
    when you are in the right context.
    And a few more hidden gems :)

Log in to reply