Reputation: 119
I'm working on Qt interface now and I have a widget in the center of the window, the widget has fixed size. when I resize the window with mouse the widget stays at the left of the window. I don't want this, but I want to stay it in the center.
I tried this;
listWidget->setFixedSize(640,480);
listWidget->adjustSize();
layout->addWidget(listWidget,Qt::AlignCenter);
but it doesn't do that.
can you help me?
Upvotes: 2
Views: 3466
Reputation: 32685
This code works fine for me :
QGridLayout * layout = new QGridLayout(this);
QListWidget * listWidget = new QListWidget(this);
listWidget->setFixedSize(640,480);
listWidget->adjustSize();
layout->addWidget(listWidget,0, 0,Qt::AlignCenter);
But an other way is to put two vertical spacers and two horizontal spacers in the layout. One should be placed at top most, the other one at the bottom, one on the left and one on the right :
Upvotes: 2