QT中按钮如何布局?

2025-03-15 19:49:52
推荐回答(3个)
回答1:

可以采用布局,然后用addStretch()
举例:
#include
#include
#include
#include
int main(int argc,char* argv[])
{
QApplication app(argc,argv);
QWidget *w=new QWidget;
QHBoxLayout *l=new QHBoxLayout(w);
QPushButton *b=new QPushButton(QObject::tr("Close"));
geometry它处于右边,如果要右下角,可以类似的布局

回答2:

可以采用布局,然后用addStretch()
举例:
#include
#include
#include
#include
int main(int argc,char* argv[])
{
QApplication app(argc,argv);
QWidget *w=new QWidget;
QHBoxLayout *l=new QHBoxLayout(w);
QPushButton *b=new QPushButton(QObject::tr("Close"));
QObject::connect(b,SIGNAL(clicked()),w,SLOT(close()));
l->addStretch();
l->addWidget(b);
w->show();
return app.exec();
}
还有别的方法,自己捉摸吧……

回答3:

一横的:QHBoxlayout,从左到右,一次排你的东西进去,addwidget()

一个竖的:QVBoxlayout从上到下,一次排你的东西进去....

一个网格的,QGridlayout,网格坐标一样,从0,0开始,指定坐标,和要放进去的东西。