3

To be more clear explaining my problem, I've done a screenshot with some notes on it, hope it helps:

QGroupBox Layout format problem

As you can see from it, I have one big QVBoxLayout for the main layout of the app, inside it I've put a Qwidget, then a QGridLayout and then a QGridLayout again. Inside this last one QGridLayout, I've put two QGroupBoxes, one in position 0,0 and one in position 0,1. Each QGroupBox has its own inner Layout, both of QGridLayout type again.

The screenshot shows that the firs QGroupBox works good, while the second one, that's quite smaller than the first, has two problems: 1) The label shoul be "Specific Operations" but it is trunked, and the only way to show it completely seems to be to put the buttons one next to the other horizontally... but I don't want it! 2) I managed to align the QGroupbox on the left of its "grid" but I need it to be on the upper-left corner of it, while it is centered for the moment... How can I achieve this?

Here is part of the code that should help you understand. Here is the kalk.h file:

class Kalk : public QWidget
{
    Q_OBJECT

public:
    Kalk(QWidget *parent = 0);

private slots:
    void kalkChange(QString);
//....
private:
    QComboBox *chooser;

    QVBoxLayout *mainLayout;
    QGridLayout *subLayout;

    QGridLayout *operationsLayout;

    QGroupBox *baseOperators;
    QGridLayout *baseOperatorsLayout;

    QGroupBox *specificOperators;
    QGridLayout *specificOperatorsLayout;
};

Then the corresponding kalk.cpp file:

Kalk::Kalk(QWidget *parent) : QWidget(parent){
    chooser = new QComboBox();
    //...
    connect(chooser,SIGNAL(currentIndexChanged(QString)),this,SLOT(kalkChange(QString)));

    mainLayout = new QVBoxLayout;
    mainLayout->setSizeConstraint(QLayout::SetFixedSize);
    subLayout = new QGridLayout;
    subLayout->setEnabled(false);
    subLayout->setSizeConstraint(QLayout::SetFixedSize);
    mainLayout->addWidget(chooser);
    mainLayout->addLayout(subLayout);

    //operationsLayout = new QHBoxLayout;
    operationsLayout = new QGridLayout;
    operationsLayout->setSizeConstraint(QLayout::SetFixedSize);
    baseOperators = new QGroupBox(tr("Base Operations"));
    baseOperatorsLayout = new QGridLayout(baseOperators);
    baseOperatorsLayout->setSizeConstraint(QLayout::SetFixedSize);

    specificOperators = new QGroupBox(tr("Specific Operations"));
    specificOperatorsLayout = new QGridLayout(specificOperators);
    specificOperatorsLayout->setSizeConstraint(QLayout::SetFixedSize);

    operationsLayout->addWidget(baseOperators,0,0);
    operationsLayout->setAlignment(baseOperators,Qt::AlignLeft);
    operationsLayout->addWidget(specificOperators,0,1);
    operationsLayout->setAlignment(specificOperators,Qt::AlignLeft);
    mainLayout->addLayout(operationsLayout);

    setLayout(mainLayout);

//...
}

In another function I load the buttons inside the Layout of the QGroupBox, but I don't think the problem is here...

eyllanesc
  • 235,170
  • 19
  • 170
  • 241
  • 1
    If you don't mind the position of the borders and the size of your groupbox, your second groupbox should expand to fill the second half of your second addLayout. That would leave plenty of space for its trunked title. Then align its content to the top-left using spacers (depending on the inner layout of the groupbox). – ymoreau Aug 16 '18 at 15:11
  • @ymoreau I can "conceptually" understand what you mean, as it is more or less what I wanted to do... The problem is that I tried varius set functions and parameters both on the QGroupBox and the QGridLayout with no success. What settings should I have to use? :-( – Andrea Casagrande Aug 16 '18 at 19:06

0 Answers0