QGroupBox: label cut and positioning inside QGridLayout

846 Views Asked by At

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

0

There are 0 best solutions below