Important: Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct
QCheckBox is too high compared to QLabel.
I am on Kubuntu 20.10.
I have Qt Creator 4.14.2, it says based on Qt 5.15.2 (GCC 7.3.1 20180303 (Red Hat 7.3.1-5), 64 bit)
I have a QCheckBox and a QLabel. They are both suppose to be on the same “line” if you know what I mean.
Imagine that I draw a horizontal line on my window.
I want to place a LABEL on the line and a little to right, I will place a CHECKBOX (with its own text).
I use setGeometry for the QCheckBox and the QLabel to set their position and sizes.
I also have a function that compares their height. If the height of QCheckBox is too little, it pushes it down.
If HeightOfCheckBox = 15 pixels
If HeightOfLabel = 20 pixels
Push down CheckBox by 5 pixels.
So, in principle, they should be at the same level.
I attached an image of what I get.
Why not use a QHBoxLayout ? It does what you want automatically.
@SGaist Ok, I tried it in there. It doesn’t show anything.
layout=new QHBoxLayout(this); layout->addWidget(CHECKWordInserted); layout->addWidget(STATICWordInserted); layout->addWidget(EDITWordToInsert); QRect rect; rect.setX(CHECKWordInsertedPosSize); rect.setY(CHECKWordInsertedPosSize); rect.setWidth(CHECKWordInsertedPosSize); rect.setHeight(CHECKWordInsertedPosSize); layout->setGeometry(rect);
Do I have to call setGeometry for CHECKWordInserted (which is a QCheckBox) and for STATICWordInserted and for EDITWordToInsert.
Is the coordinate relative to the QHBoxLayout?
Pl45m4 last edited by
. It doesn’t show anything.
Did you forgot to add your layout to your mainLayout or set it as mainLayout if your widget had no layout already?
No you usually dont need
setGeometrywhen using layouts.
Thank You last edited by
Maybe this will help
@Pl45m4 Well, how else is it going to know that I want this layout thing to be positioned below the textbox (QLabel) "Copy character count (min 1 and max 3)"?
I am not using layouts everywhere. I do all my positioning myself except there is this problem with the level of the checkbox text.
This time, I added
but again, I don't see it.
When you pass a parent to a layout, it is automatically applied to that parent.
Positioning everything yourself is pretty rarely done. Properly using layouts, in your case, a combination of QVBoxLayout and QHBoxLayout or a QGridLayout will make things easier to maintain especially with screens of different resolutions.
Pl45m4 last edited by
except there is this problem with the level of the checkbox text.
A problem you wouldn't have when you use layouts everywhere :)
HBox and VBox Layouts will make your widgets allign properly in rows and columns.
@Pl45m4 OK I tried it in a test program and looks like it is able to align the text of a button and QCheckBox and a QLabel.
But how am I suppose to have control on the size of buttons and EDITBOXes?
Sounds like a QGridLayout.
Can you show a mock-up of what you want to achieve ? It would help us help you.