Ironus
29th January 2015, 17:38
First of all, hello everyone!
I'm not a native speaker, so really sorry for my english. I'll do my best to be as clear as only possible.
I've started my journey with Qt few days ago, so I'm not very experienced with it. I'm trying to make simple application with QScrollArea and QTextEdit fields.
I want to add QPushButtons to QScrollArea dynamically - on button press. Everything works fine, but positioning elements in QScrollArea is ruined when there is less than few buttons added (everything explained in screenshot in attachments). I've tried to setContentsMargins(0, 0, 0, 0) and setAligment(Qt::AlignTop), but it doesn't work as I thought it will be.
Here is my code where I'm adding QScrollArea:
numberOfGridBoxRows = 0;
gridGroupBox = new QGroupBox(tr("Próbki"));
layout = new QGridLayout;
samplesWidget = new QWidget();
samplesButtonsLayout = new QGridLayout();
samplesButtonsLayout->setContentsMargins(0, 0, 0, 0);
samplesWidget->setLayout(samplesButtonsLayout);
samplesScroller = new QScrollArea();
samplesScroller->setWidgetResizable(true);
samplesScroller->setContentsMargins(0, 0, 0, 0);
samplesScroller->setAlignment(Qt::AlignTop);
samplesScroller->setWidget(samplesWidget);
smallEditor = new QTextEdit;
smallEditor->setPlainText(tr(""));
smallEditor->setMinimumWidth(300);
smallEditor->setMinimumHeight(300);
layout->addWidget(samplesScroller, 0, 0, 1, 1);
layout->addWidget(smallEditor, 0, 1, 1, 1);
layout->setColumnStretch(0, 100);
layout->setColumnMinimumWidth(0, 150);
layout->setColumnStretch(1, 60);
gridGroupBox->setLayout(layout);
And here is code where I'm adding QPushButtons to QScrollArea widget (part of another function):
// I've changed parameters in button constructor here, because normally as a button name is value provided by user
QPushButton *showSampleButton = new QPushButton(tr("button"), this);
samplesScroller->ensureWidgetVisible(samplesWidget, 0, 0);
samplesButtonsLayout->addWidget(showSampleButton, numberOfGridBoxRows++, 0, 1, 1, Qt::AlignTop);
I'll be very thankfull for help.
Best regards,
Ironus
10915
I'm not a native speaker, so really sorry for my english. I'll do my best to be as clear as only possible.
I've started my journey with Qt few days ago, so I'm not very experienced with it. I'm trying to make simple application with QScrollArea and QTextEdit fields.
I want to add QPushButtons to QScrollArea dynamically - on button press. Everything works fine, but positioning elements in QScrollArea is ruined when there is less than few buttons added (everything explained in screenshot in attachments). I've tried to setContentsMargins(0, 0, 0, 0) and setAligment(Qt::AlignTop), but it doesn't work as I thought it will be.
Here is my code where I'm adding QScrollArea:
numberOfGridBoxRows = 0;
gridGroupBox = new QGroupBox(tr("Próbki"));
layout = new QGridLayout;
samplesWidget = new QWidget();
samplesButtonsLayout = new QGridLayout();
samplesButtonsLayout->setContentsMargins(0, 0, 0, 0);
samplesWidget->setLayout(samplesButtonsLayout);
samplesScroller = new QScrollArea();
samplesScroller->setWidgetResizable(true);
samplesScroller->setContentsMargins(0, 0, 0, 0);
samplesScroller->setAlignment(Qt::AlignTop);
samplesScroller->setWidget(samplesWidget);
smallEditor = new QTextEdit;
smallEditor->setPlainText(tr(""));
smallEditor->setMinimumWidth(300);
smallEditor->setMinimumHeight(300);
layout->addWidget(samplesScroller, 0, 0, 1, 1);
layout->addWidget(smallEditor, 0, 1, 1, 1);
layout->setColumnStretch(0, 100);
layout->setColumnMinimumWidth(0, 150);
layout->setColumnStretch(1, 60);
gridGroupBox->setLayout(layout);
And here is code where I'm adding QPushButtons to QScrollArea widget (part of another function):
// I've changed parameters in button constructor here, because normally as a button name is value provided by user
QPushButton *showSampleButton = new QPushButton(tr("button"), this);
samplesScroller->ensureWidgetVisible(samplesWidget, 0, 0);
samplesButtonsLayout->addWidget(showSampleButton, numberOfGridBoxRows++, 0, 1, 1, Qt::AlignTop);
I'll be very thankfull for help.
Best regards,
Ironus
10915