HBoxlayout items starting on the left?
-
I've been trying to use the HBoxlayout and I'm trying to get all the QToolButtons to start and clump on the left hand side (unlike the screenshot). I've been adding them to the HBoxLayout with Qt::alignLeft. What am I doing wrong?
QTextBrowser *centralWidget = new QTextBrowser; centralWidget->setPlainText(tr("Central widget")); BorderLayout *layout = new BorderLayout; QWidget *menu = new QWidget(); QVBoxLayout *vboxLayout = new QVBoxLayout(); QWidget *menu1 = new QWidget(); vboxLayout->addWidget(menu1); QHBoxLayout *hboxLayout = new QHBoxLayout(); QToolButton *b1 = new QToolButton(); QToolButton *b2 = new QToolButton(); hboxLayout->addWidget(b1,Qt::AlignLeft); hboxLayout->addWidget(b2,Qt::AlignLeft); menu1->setLayout(hboxLayout); menu->setLayout(vboxLayout); QPalette pal = palette(); // set black background pal.setColor(QPalette::Window, Qt::black); menu->setAutoFillBackground(true); menu->setPalette(pal); QPalette pal2 = palette(); // set dark red background pal2.setColor(QPalette::Window, Qt::darkRed); menu1->setAutoFillBackground(true); menu1->setPalette(pal2); layout->addWidget(centralWidget, BorderLayout::Center); layout->addWidget(menu, BorderLayout::North); layout->addWidget(createLabel("West"), BorderLayout::West); layout->addWidget(createLabel("East 1"), BorderLayout::East); layout->addWidget(createLabel("East 2") , BorderLayout::East); layout->addWidget(createLabel("South"), BorderLayout::South); setLayout(layout); setWindowTitle(tr("Border Layout"));
-
I've been trying to use the HBoxlayout and I'm trying to get all the QToolButtons to start and clump on the left hand side (unlike the screenshot). I've been adding them to the HBoxLayout with Qt::alignLeft. What am I doing wrong?
QTextBrowser *centralWidget = new QTextBrowser; centralWidget->setPlainText(tr("Central widget")); BorderLayout *layout = new BorderLayout; QWidget *menu = new QWidget(); QVBoxLayout *vboxLayout = new QVBoxLayout(); QWidget *menu1 = new QWidget(); vboxLayout->addWidget(menu1); QHBoxLayout *hboxLayout = new QHBoxLayout(); QToolButton *b1 = new QToolButton(); QToolButton *b2 = new QToolButton(); hboxLayout->addWidget(b1,Qt::AlignLeft); hboxLayout->addWidget(b2,Qt::AlignLeft); menu1->setLayout(hboxLayout); menu->setLayout(vboxLayout); QPalette pal = palette(); // set black background pal.setColor(QPalette::Window, Qt::black); menu->setAutoFillBackground(true); menu->setPalette(pal); QPalette pal2 = palette(); // set dark red background pal2.setColor(QPalette::Window, Qt::darkRed); menu1->setAutoFillBackground(true); menu1->setPalette(pal2); layout->addWidget(centralWidget, BorderLayout::Center); layout->addWidget(menu, BorderLayout::North); layout->addWidget(createLabel("West"), BorderLayout::West); layout->addWidget(createLabel("East 1"), BorderLayout::East); layout->addWidget(createLabel("East 2") , BorderLayout::East); layout->addWidget(createLabel("South"), BorderLayout::South); setLayout(layout); setWindowTitle(tr("Border Layout"));
@jkwok678 Take a look at https://doc.qt.io/qt-5/qspaceritem.html
Especially "QHBoxLayout addSpacing(), addStretch(), insertSpacing(), insertStretch()" -
Hi,
What changes do you have in mind ?
-
For example what happens with the spacers, when the window size isn't big enough to justify them being there, as in it distorts the other elements in the GUI?