Layout Alignmet not respected
Solved
General and Desktop
-
Dear all,
I don't understand because my custom class that inherit from QLabel not respect the Center Alignment.
LanguagesMenu::LanguagesMenu(QWidget *parent) : SkeletronView(parent) { this->setObjectName("LanguagesMenu"); QWidget* widget = new QWidget(); widget->setMaximumSize(600, 400); itBtn = new ZoomLabel(":/Images/Flags/itFlag.png", "itFlag"); enBtn = new ZoomLabel(":/Images/Flags/enFlag.png", "enFlag"); frBtn = new ZoomLabel(":/Images/Flags/frFlag.png", "frFlag"); QVBoxLayout* layout = new QVBoxLayout(widget); layout->addWidget(itBtn, Qt::AlignHCenter); layout->addWidget(enBtn, Qt::AlignHCenter); layout->addWidget(frBtn, Qt::AlignHCenter); layout->setContentsMargins(10, 10, 10, 10); layout->setSpacing(1); widget->setLayout(layout); hideSettingsBtn(); // hideBackBtn(); hideForwardBtn(); // hideHomeBtn(); handler(); SkeletronView::setCentralWidget(widget); } void LanguagesMenu::handler(void) { itBtn->setMaximumWidth(400); itBtn->setAlignment(Qt::AlignCenter); enBtn->setMaximumWidth(500); enBtn->setAlignment(Qt::AlignCenter); frBtn->setMaximumWidth(400); frBtn->setAlignment(Qt::AlignCenter); }
-
@Simof said in Layout Alignmet not respected:
layout->addWidget(itBtn, Qt::AlignHCenter);
Second parameter is actually stretch: https://doc.qt.io/qt-5/qboxlayout.html#addWidget