how to setAlignment of QGroupBox
-
By main widget you understand a "mother widget" that would contain the groupbox & the terminal widget, right?
Yes.
So now where do you add this groupbox ? You should add this groupbox inside another layout so that it is laid properly.
@p3c0 said in how to setAlignment of QGroupBox:
Yes.
So now where do you add this groupbox ? You should add this groupbox inside another layout so that it is laid properly.
So I currently have something lke groupBox(vbox(terminalWidget())) and I think from what you're saying, I should have something like ContainerWidget(vbox(groupBox(terminalWidget))), is that correct? Any idea what kind of container widget I can use for this? Or better, vbox(groupBox(terminalWidget)) should do as well, shouldn't it?
-
@p3c0 said in how to setAlignment of QGroupBox:
Yes.
So now where do you add this groupbox ? You should add this groupbox inside another layout so that it is laid properly.
So I currently have something lke groupBox(vbox(terminalWidget())) and I think from what you're saying, I should have something like ContainerWidget(vbox(groupBox(terminalWidget))), is that correct? Any idea what kind of container widget I can use for this? Or better, vbox(groupBox(terminalWidget)) should do as well, shouldn't it?
@p3c0 said in how to setAlignment of QGroupBox:
ContainerWidget(vbox(groupBox(terminalWidget))), is that correct?
Yes. You can use
QDialogas the container widget.But I don't want it to be in abother dialog and it already is in a QTabWidget....I should use that as the outer most layer probably...
-
@p3c0 said in how to setAlignment of QGroupBox:
@cerr Ok. But remember to add that groupbox inside a layout.
So what actually happens in my application is:
MainWindow->QTabWidget->session->setupSession->addTerminal->QVBoxWidget(QGroupBox->terminalWidget) and you suggest i'd better be like mainwindow->QVBoxWidget(QTabWidget->session->setupSession->addTerminal->QGroupBox->terminalWidget) ?
Will that change things? -
@cerr No. The earlier one.
MainWindow->QTabWidget->session->setupSession->addTerminal->QVBoxWidget(QGroupBox->terminalWidget)But I dont see that happening in your original code.
QGroupBox *groupBox = new QGroupBox(tr("Test"), parent); //<--- This should be added in a layout too. groupBox->setAlignment(Qt::AlignLeft); QWidget* terminalWidget = terminal->terminalWidget(); QVBoxLayout *vbox = new QVBoxLayout; vbox->addWidget(terminalWidget); groupBox->setLayout(vbox); // <--- This sets layout inside it terminalWidget ->show(); if (/*terminalWidget*/groupBox) /*terminalWidget*/groupBox->setFocus(); groupBox->show(); -
@cerr No. The earlier one.
MainWindow->QTabWidget->session->setupSession->addTerminal->QVBoxWidget(QGroupBox->terminalWidget)But I dont see that happening in your original code.
QGroupBox *groupBox = new QGroupBox(tr("Test"), parent); //<--- This should be added in a layout too. groupBox->setAlignment(Qt::AlignLeft); QWidget* terminalWidget = terminal->terminalWidget(); QVBoxLayout *vbox = new QVBoxLayout; vbox->addWidget(terminalWidget); groupBox->setLayout(vbox); // <--- This sets layout inside it terminalWidget ->show(); if (/*terminalWidget*/groupBox) /*terminalWidget*/groupBox->setFocus(); groupBox->show();@p3c0 said in how to setAlignment of QGroupBox:
@cerr No. The earlier one.
MainWindow->QTabWidget->session->setupSession->addTerminal->QVBoxWidget(QGroupBox->terminalWidget)But I dont see that happening in your original code.
QGroupBox *groupBox = new QGroupBox(tr("Test"), parent); //<--- This should be added in a layout too. groupBox->setAlignment(Qt::AlignLeft); QWidget* terminalWidget = terminal->terminalWidget(); QVBoxLayout *vbox = new QVBoxLayout; vbox->addWidget(terminalWidget); groupBox->setLayout(vbox); // <--- This sets layout inside it terminalWidget ->show(); if (/*terminalWidget*/groupBox) /*terminalWidget*/groupBox->setFocus(); groupBox->show();Sorry,
Yeah, I had changed it in the meantime to:
QGroupBox *groupBox = new QGroupBox(tr("Test"), parent); groupBox->setAlignment(Qt::AlignLeft); QWidget* terminalWidget = terminal->terminalWidget(); QVBoxLayout *vbox = new QVBoxLayout; vbox->addWidget(terminalWidget); vbox->addWidget(groupBox); //groupBox->setLayout(vbox); <- if i remove the comment, it won't start my application at all... terminalWidget ->show(); if (/*terminalWidget*/groupBox) /*terminalWidget*/groupBox->setFocus(); -
@p3c0 said in how to setAlignment of QGroupBox:
@cerr So now set
vboxas a layout to its parent widget.Did you mean like?
QVBoxLayout *vbox = new QVBoxLayout; vbox->addWidget(terminalWidget); vbox->addWidget(groupBox); vbox->addWidget(parent); groupBox->setLayout(vbox); terminalWidget ->show(); ``` - that doesn't let me open my application... -
@cerr Probably something like this. Assuming
QDialogis my main widget which contains groupbox.QVBoxLayout *mainLayout = new QVBoxLayout; myDialog->setLayout(mainLayout); //Now add widgets into this layout mainLayout->addWidget(groupBox);// groupbox first mainLayout->addWidget(terminalWidget);Now in your case if you want to add
terminalWidgetinside a groupbox's layout you can create new one and add into it keeping mainLayout as it is. -
@cerr Probably something like this. Assuming
QDialogis my main widget which contains groupbox.QVBoxLayout *mainLayout = new QVBoxLayout; myDialog->setLayout(mainLayout); //Now add widgets into this layout mainLayout->addWidget(groupBox);// groupbox first mainLayout->addWidget(terminalWidget);Now in your case if you want to add
terminalWidgetinside a groupbox's layout you can create new one and add into it keeping mainLayout as it is.@p3c0 said in how to setAlignment of QGroupBox:
Thanks for pitching in, I guess this is what I was missing. I now have this (which I can work with going forward):
Terminal* Session::addTerminal(QWidget* parent) { QGroupBox *groupBox = new QGroupBox(tr("Test"), parent); groupBox->setAlignment(Qt::AlignLeft); QVBoxLayout *vbox = new QVBoxLayout; groupBox->setLayout(vbox); vbox->addWidget(groupBox); Terminal* terminal = new Terminal(parent); connect(terminal, SIGNAL(activated(int)), this, SLOT(setActiveTerminal(int))); connect(terminal, SIGNAL(manuallyActivated(Terminal*)), this, SIGNAL(terminalManuallyActivated(Terminal*))); connect(terminal, SIGNAL(titleChanged(int,QString)), this, SLOT(setTitle(int,QString))); connect(terminal, SIGNAL(keyboardInputBlocked(Terminal*)), this, SIGNAL(keyboardInputBlocked(Terminal*))); connect(terminal, SIGNAL(silenceDetected(Terminal*)), this, SIGNAL(silenceDetected(Terminal*))); connect(terminal, SIGNAL(destroyed(int)), this, SLOT(cleanup(int))); m_terminals.insert(terminal->id(), terminal); QWidget* terminalWidget = terminal->terminalWidget(); vbox->addWidget(terminalWidget); terminalWidget->show(); if (groupBox) groupBox->setFocus(); return terminal; }But now back to the top, while it looks like this now: https://postimg.org/image/viahdjbwp/ how do I get the GroupBox label aligned to the left?
-
@cerr Here is a small example that demonstrates it:
int main(int argc, char *argv[]) { QApplication app(argc, argv); QDialog d; d.resize(400, 400); d.show(); QVBoxLayout mainLayout; d.setLayout(&mainLayout); QGroupBox box; box.setTitle("MyGroupBox"); mainLayout.addWidget(&box); QLabel label("MyLabel"); mainLayout.addWidget(&label); return app.exec(); }You can see the
QGroupBoxproperly aligned to the left. Here the Groupbox is added into the main widget's layout. Try to do in the similar way. -
@cerr Here is a small example that demonstrates it:
int main(int argc, char *argv[]) { QApplication app(argc, argv); QDialog d; d.resize(400, 400); d.show(); QVBoxLayout mainLayout; d.setLayout(&mainLayout); QGroupBox box; box.setTitle("MyGroupBox"); mainLayout.addWidget(&box); QLabel label("MyLabel"); mainLayout.addWidget(&label); return app.exec(); }You can see the
QGroupBoxproperly aligned to the left. Here the Groupbox is added into the main widget's layout. Try to do in the similar way.@p3c0 said in how to setAlignment of QGroupBox:
Thanks but I want the
box.setTitle("MyGroupBox"); title to be left aligned, so I altered your example code to:QGroupBox box; box.setTitle("MyGroupBox"); box.setAlignment(Qt::AlignLeft); mainLayout.addWidget(&box);but like in my application above, the title stays centered, can it be left aligned at all?
This is from http://doc.qt.io/qt-5/qgroupbox.html#alignment-prop:alignment : Qt::Alignment
This property holds the alignment of the group box title.
-
Hi,
Which window manager are you using ?
I just tested on macOS and the alignment is working properly (self built 5.7)
-
Hi,
Which window manager are you using ?
I just tested on macOS and the alignment is working properly (self built 5.7)
-
@cerr I was just trying to find out what style was you application using. I assumed you might use
qDebug()which would have properly printed the object info. Anyway try this:QApplication::style()->objectName();If it prints "fusion" (atleast on my system it does, KDE too here) then the the problem might be related to this bug which says it was fixed in
Qt 5.6.1. Can you try the newer version ? -
@cerr I was just trying to find out what style was you application using. I assumed you might use
qDebug()which would have properly printed the object info. Anyway try this:QApplication::style()->objectName();If it prints "fusion" (atleast on my system it does, KDE too here) then the the problem might be related to this bug which says it was fixed in
Qt 5.6.1. Can you try the newer version ?