QGroupBox:在QGridLayout

时间:2018-08-16 15:01:07

标签: c++ qt qgridlayout qgroupbox

为更清楚地说明我的问题,我已经完成了屏幕截图,上面有一些注释,希望对您有所帮助:

QGroupBox布局格式问题

从中可以看到,我的应用程序主布局有一个大的QVBoxLayout,在其中放置了Qwidget,然后是QGridLayout,然后是再次QGridLayout。 在最后一个QGridLayout中,我放入了两个QGroupBoxes,一个位于0,0位置,另一个位于0,1位置。每个QGroupBox都有自己的内部布局,两者均为QGridLayout类型。

该屏幕截图显示,第一QGroupBox效果很好,而第二个要比第一个小得多,但有两个问题: 1)标签应该是“ Specific Operations”(特定操作),但它是中继的,要完全显示它,唯一的方法似乎是将按钮水平地并排放置……但是我不想要它! 2)我设法将QGroupbox对齐到其“网格”的左侧,但是我需要将其放在它的左上角,同时暂时将其居中...如何实现此目的? ?

这是应帮助您理解的代码的一部分。这是kalk.h文件:

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;
};

然后是相应的kalk.cpp文件:

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);

//...
}

在另一个函数中,我将按钮加载到QGroupBox的Layout内,但我不认为问题出在这里...

0 个答案:

没有答案
相关问题