QGridLayout
は中央のウィジェット内にあり、固定サイズのウィジェット(内部ウィジェットと呼ばれます)にはボタンでいっぱいにQGridLayout
が含まれています。内部ウィジェットのサイズは、グリッド内にいくつのボタンがあるかによって決まり、正確なフィット(ボタンの間にスペースはありません。FixedSize
のポリシーがボタンのコンストラクターに適用されます)、すべてのボタンのサイズとポリシーはコンストラクタ。今、私がインナーウィジェットをどんな種類のレイアウトにも入れないと、それはうまく動作し、素敵な四角いボタンが得られます。しかし、内側のウィジェットをグリッドレイアウトに配置すると、すべてのボタンが突然サイズを変更し、ウィジェットもサイズを維持するようには見えません。どうして?FixedSizeを使用したウィジェットは、そのサイズをいつでも変更します
編集:MyButtonTable:
MyButtonTable::MyButtonTable(QWidget *parent) : QWidget(parent), array()
{
size_x = 2;
size_y = 2;
QGridLayout* layout = new QGridLayout();
for(size_t x = 0; x < size_x; x++) {
this->array.push_back(std::vector<MyRightClickButton*>());
}
for(size_t x = 0; x < size_x; x++) {
for(size_t y = 0; y < size_y; y++) {
this->array[x].push_back(new button_t());
QObject::connect(array[x][y], SIGNAL(rightClicked()), this, SLOT(internalRightClick()));
QObject::connect(array[x][y], SIGNAL(clicked()), this, SLOT(internalClick()));
layout->addWidget(array[x][y], x, y);
}
}
layout->setSpacing(0);
layout->setContentsMargins(0,0,0,0);
this->setLayout(layout);
this->setSizePolicy(QSizePolicy::Fixed, QSizePolicy::Fixed);
this->setMinimumSize(QSize(0,0));
this->resize(QSize(10*size_y,10*size_x));
}
MyRightClickButton(QWidget *parent = 0):QPushButton(parent) {
marked = false;
this->setSizePolicy(QSizePolicy::Fixed, QSizePolicy::Fixed);
this->setMinimumSize(QSize(0,0));
this->resize(QSize(10,10));
}
私にとっては、レイアウトには独自のサイズポリシーがあり、ウィジェットの固定サイズは無視されます。 @RomaValcer – Athena
@Athenaとそれについて何ができますか? – RomaValcer
私は経験した限り、どちらかを使うべきです。 – Athena