Max
Max

Reputation: 21

Qt - Default Alignment for addWidget in VBoxLayout

I'm struggling with the Alignment-Parameter at the addWidget(widget, stretch, alignment) method from a QVBoxlayout.

I'm adding a QTableview to my layout:

Without an alignment argument everything works fine - my tableview fills the entire space in the layout.

Now, I want to know, what is the default alignment used, so that I can add that to my method-call. The documentation says, without an alignment argument, the default-alignment-argument is zero. But when I call addWidget with "0" as my alignment-argument, pycharm is complaining about wrong type, int instead of Qt:: Alignment...

Upvotes: 2

Views: 810

Answers (1)

Zlatomir
Zlatomir

Reputation: 7034

The good part of opensource software is that you can take a look at the source, the code is:

void addWidget(QWidget *, int stretch = 0, Qt::Alignment alignment = Qt::Alignment());

So call your the addWidget method with the equivalent of Qt::Alignment() as the last argument:

yourLayout.addWidget(yourWidget, 0, Qt.Alignment())  # Python
yourLayout->addWidget(yourWidget, 0, {});           // C++

Upvotes: 3

Related Questions