QGroupBox and positioning a button on a QGroupBox
-
Hello all,
I am creating a QGroupBox on my QMainWindow window.QGroupBox *GROUPBOXChemicalEquation; GROUPBOXChemicalEquation=new QGroupBox(this); GROUPBOXChemicalEquation->setGeometry(X, Y, width, height); GROUPBOXChemicalEquation->setTitle("Chemical Equation");
So, that looks fine and good.
Then I want to place some controls on it. Let’s say, I want to put this button:BUTTONCopyEnergy3=new QPushButton(“Copy”, GROUPBOXChemicalEquation); <====notice the GROUPBOXChemicalEquation BUTTONCopyEnergy3->setGeometry(0, 0, BUTTONCopyEnergy3PosSize[2], BUTTONCopyEnergy3PosSize[3]);
THE PROBLEM:
The problem is the position of the button. It positions the button over the header text: Chemical Equation -
Hello all,
I am creating a QGroupBox on my QMainWindow window.QGroupBox *GROUPBOXChemicalEquation; GROUPBOXChemicalEquation=new QGroupBox(this); GROUPBOXChemicalEquation->setGeometry(X, Y, width, height); GROUPBOXChemicalEquation->setTitle("Chemical Equation");
So, that looks fine and good.
Then I want to place some controls on it. Let’s say, I want to put this button:BUTTONCopyEnergy3=new QPushButton(“Copy”, GROUPBOXChemicalEquation); <====notice the GROUPBOXChemicalEquation BUTTONCopyEnergy3->setGeometry(0, 0, BUTTONCopyEnergy3PosSize[2], BUTTONCopyEnergy3PosSize[3]);
THE PROBLEM:
The problem is the position of the button. It positions the button over the header text: Chemical Equation@stretchthebits
As ever, you are supposed to place a layout and not use absolute size/positioning to place widgets on boxes. Have you looked at the basic example at https://doc.qt.io/qt-5/qgroupbox.html#details ? -
@stretchthebits
As ever, you are supposed to place a layout and not use absolute size/positioning to place widgets on boxes. Have you looked at the basic example at https://doc.qt.io/qt-5/qgroupbox.html#details ?@JonB That seems to be fine for a simple arrangement but I am not sure how to have the look as can been in the screenshot.
And why not calculate and position controls ourselves? -
@JonB That seems to be fine for a simple arrangement but I am not sure how to have the look as can been in the screenshot.
And why not calculate and position controls ourselves?@stretchthebits said in QGroupBox and positioning a button on a QGroupBox:
And why not calculate and position controls ourselves?
You can if you want to do all the calculations by yourself. But this is not trivial and what's the layout manager is for.