Important: Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct
Help with aligning child widgets in parent widget
I have a _mainwindow_ which is used to contain several other widgets. I use _QVBoxLayout_ and _QHBoxLayout_ to align these widgets in the _mainwindow_ as,
NewWidget *nw = new NewWidget();
NewWidgetTwo *nwt = new NewWidgetTwo();
NewWidgetThree *nwth = new NewWidgetThree();
QHboxLayout *hbl = new QHBoxLayout(); QVboxLayout *vbl = new QVBoxLayout(); hbl->addWidget(nw); hbl->addWidget(nwt); vbl->addWidget(nwth); vbl->addLayout(hbl);
I tried using the stretch property and also the alignment options in Qt like Qt::AlignLeft, Qt::AlignLeading etc but I'm not able to achieve the desired alignment. Are there any other ways in Qt to position widgets?
Sam last edited by
bq. I’m not able to achieve the desired alignment
Can you attach an image of your requirement as well as the output you are getting now. You can also use a gridlayout
@QGridLayout *gd1 = new QGridLayout();
I'm not allowed to attach a screenshot so I just made a mock up of how it should look and what the actual output is. Each red rectangle represents a widget and the blue rectangle is an image within the widget.
EDIT: Okay I'm not able to upload a picture from my computer. Could somebody tell me how to do this?
andre last edited by
Just put your image at some public location, and use its URL. I use my public dropbox folder for this, but there are plenty of other options. You cannot upload images to this forum directly.
Grr! My office does not have access to dropbox, Google drive etc. I'll upload the picture when I'm at home. Thanks so much Andre :)
qxoz last edited by
Maybe some of this hostings are accesseble for your office:
Haha! It's funny how I clicked on each one of these links and it kept showing "Content blocked by your organization" :)
My internet is down at home. I'll upload the file soon. Sorry!