0

私はこれをしたい: マウスを押して移動するメインウィンドウを拡大すると、ボタンが常にメインウィンドウの端にあることを確認するために、(ボタンのような) ウィジェットをそれに応じて移動させます (ボタンのサイズを変更するのではありません)。私はこのようにそれを行うことができます:

void MainWindow::resizeEvent(QResizeEvent *e)
{
int x,y,newx,newy,resizex,resizey;
newx = this->width();
newy = this->height();
resizex = newx - mainwindowWidth;
resizey = newy - mainwindowHeight;
x = ui->button->pos().x();
y = ui->button->pos().y();
ui->button->move(x+resizex, y+resizey);
mainwindowWidth = newx;
mainwindowHeight = newy;
}

しかし、それはとても複雑です。QPushButton には、この仕事を簡単に行うための属性がありますか? あなたの答えを待っています。どんなアドバイスも役に立ちます。前もって感謝します。

4

1 に答える 1

0

プッシュボタンをレイアウトに追加し、スペーサーを追加してボタンを端まで押すことができます。

例を次に示します。

QHBoxLayout *hlayout = new QHBoxLayout;
ui->verticalLayout->addLayout(hlayout);

QPushButton *button = new QPushButton("Button");
hlayout->addWidget(button);
QSpacerItem *item = new QSpacerItem(1,1, QSizePolicy::Expanding, QSizePolicy::Fixed);    
hlayout->addSpacerItem(item);
于 2013-05-07T10:10:36.147 に答える