Qt-interest Archive, February 2007
QGridLayout is not shown on QScrollArea
Message 1 in thread
Hi There,
I have the problem as per the subject and both the hope that someone could
help me.
The situation is that there are:
QScrollArea ScrollArea;
QGridLayout *pScrollLayout;
In the constructor I add ScrollArea to the main layout of the QMainWindow:
ui.hboxLayout1->setAlignment(Qt::AlignTop);
ui.hboxLayout1->addWidget(&ScrollArea);
Then what I do is:
Create a QVector what holds a struct of four pointers (2x QLabel*, 1x
QCheckBox* and 1x QComboBox*). Each objects are initialized with a new
statement and put into the QVector like:
struct StructLayoutItem {
QLabel *pLabelItemName;
QCheckBox *pCheckBoxUpdate;
QComboBox *pComboBoxValues;
QLabel* pLabelDataType;
};
std::vector<struct StructLayoutItem> LayoutItems;
and then a few times if for():
struct StructLayoutItem LayoutItem;
LayoutItem.pLabelItemName = new QLabel("");
LayoutItem.pCheckBoxUpdate = new QCheckBox("");
LayoutItem.pComboBoxValues = new QComboBox();
LayoutItem.pComboBoxValues->setEditable(true);
LayoutItem.pLabelDataType = new
QLabel(StringDataType);
LayoutItems.push_back(LayoutItem);
Then I go through the QVector and elements to the QGridLayout:
int Row = 0;
pScrollLayout = new QGridLayout();
for (i = 0; i < LayoutItems.size(); i++) {
pScrollLayout->addWidget(LayoutItems.at(i).pLabelItemName,
Row++, 1);
pScrollLayout->addWidget(LayoutItems.at(i).pCheckBoxUpdate,
Row, 0);
pScrollLayout->addWidget(LayoutItems.at(i).pComboBoxValues,
Row, 1);
pScrollLayout->addWidget(LayoutItems.at(i).pLabelDataType,
Row++, 2);
}
I even check if the layout has the items (and yes, it has):
int x = pScrollLayout->rowCount();
int y = pScrollLayout->columnCount();
And I add the layout to the scroll area:
ScrollArea.setWidget(pScrollLayout->widget());
And then... nothing is shown in the ScrollArea.
If I just do (after the consturctor did its addition to the ui.hBoxLayout1):
ScrollArea.setWidget(new QLabel("blah blah"));
that is fine and the QLabel is there.
I even tried update() and repaint() but none of them helped.
Do you have an idea what is wrong in the code up there?
Thanks,
Sandor
Message 2 in thread
On 21.02.07 14:33:49, Hadas Sandor wrote:
> Then I go through the QVector and elements to the QGridLayout:
> int Row = 0;
> pScrollLayout = new QGridLayout();
At this point you have a layout that is not associated with any widget
and has no parent.
> And I add the layout to the scroll area:
> ScrollArea.setWidget(pScrollLayout->widget());
See above, you don't have a widget associated with the layout, so
widget() will return 0.
What you want to do is something like
QWidget* w = new QWidget(ScrollArea)
pScrollLayout = new QGridLayout(w);
ScrollArea->setWidget(w);
Andreas
--
[ signature omitted ]
Message 3 in thread
> pScrollLayout = new QGridLayout();
you need to pass a widget to the new layout!
> ScrollArea.setWidget(pScrollLayout->widget());
this will just setWidget(0) as you didnt give the layout a widget.
Cheers,
Peter
--
[ signature omitted ]
Message 4 in thread
Actually, I found out one thing, setVisible was missing. So if the following
change is made, the items show up.
Unfortunately the items show up in separate windows instad on the
QGridLayout regardless of the addWidget call. Hmmm, does anyone know why?
for (i = 0; i < LayoutItems.size(); i++) {
pScrollLayout->addWidget(LayoutItems.at(i).pLabelItemName, Row++, 1);
LayoutItems.at(i).pLabelItemName->setVisible(true);
pScrollLayout->addWidget(LayoutItems.at(i).pCheckBoxUpdate, Row, 0);
LayoutItems.at(i).pCheckBoxUpdate->setVisible(true);
pScrollLayout->addWidget(LayoutItems.at(i).pComboBoxValues, Row, 1);
LayoutItems.at(i).pComboBoxValues->setVisible(true);
pScrollLayout->addWidget(LayoutItems.at(i).pLabelDataType, Row++, 2);
LayoutItems.at(i).pLabelDataType->setVisible(true);
}
Sandor
-----Original Message-----
From: qt-interest-request@xxxxxxxxxxxxx
[mailto:qt-interest-request@xxxxxxxxxxxxx]On Behalf Of Hadas Sandor
Sent: 21/02/2007 15:34
To: 'qt-interest@xxxxxxxxxxxxx'
Subject: QGridLayout is not shown on QScrollArea
Hi There,
I have the problem as per the subject and both the hope that someone could
help me.
The situation is that there are:
QScrollArea ScrollArea;
QGridLayout *pScrollLayout;
In the constructor I add ScrollArea to the main layout of the QMainWindow:
ui.hboxLayout1->setAlignment(Qt::AlignTop);
ui.hboxLayout1->addWidget(&ScrollArea);
Then what I do is:
Create a QVector what holds a struct of four pointers (2x QLabel*, 1x
QCheckBox* and 1x QComboBox*). Each objects are initialized with a new
statement and put into the QVector like:
struct StructLayoutItem {
QLabel *pLabelItemName;
QCheckBox *pCheckBoxUpdate;
QComboBox *pComboBoxValues;
QLabel* pLabelDataType;
};
std::vector<struct StructLayoutItem> LayoutItems;
and then a few times if for():
struct StructLayoutItem LayoutItem;
LayoutItem.pLabelItemName = new QLabel("");
LayoutItem.pCheckBoxUpdate = new QCheckBox("");
LayoutItem.pComboBoxValues = new QComboBox();
LayoutItem.pComboBoxValues->setEditable(true);
LayoutItem.pLabelDataType = new
QLabel(StringDataType);
LayoutItems.push_back(LayoutItem);
Then I go through the QVector and elements to the QGridLayout:
int Row = 0;
pScrollLayout = new QGridLayout();
for (i = 0; i < LayoutItems.size(); i++) {
pScrollLayout->addWidget(LayoutItems.at(i).pLabelItemName,
Row++, 1);
pScrollLayout->addWidget(LayoutItems.at(i).pCheckBoxUpdate,
Row, 0);
pScrollLayout->addWidget(LayoutItems.at(i).pComboBoxValues,
Row, 1);
pScrollLayout->addWidget(LayoutItems.at(i).pLabelDataType,
Row++, 2);
}
I even check if the layout has the items (and yes, it has):
int x = pScrollLayout->rowCount();
int y = pScrollLayout->columnCount();
And I add the layout to the scroll area:
ScrollArea.setWidget(pScrollLayout->widget());
And then... nothing is shown in the ScrollArea.
If I just do (after the consturctor did its addition to the ui.hBoxLayout1):
ScrollArea.setWidget(new QLabel("blah blah"));
that is fine and the QLabel is there.
I even tried update() and repaint() but none of them helped.
Do you have an idea what is wrong in the code up there?
Thanks,
Sandor
Message 5 in thread
Aye, thanks. :)
-----Original Message-----
From: qt-interest-request@xxxxxxxxxxxxx
[mailto:qt-interest-request@xxxxxxxxxxxxx]On Behalf Of Andreas Pakulat
Sent: 21/02/2007 16:16
To: qt-interest@xxxxxxxxxxxxx
Subject: Re: QGridLayout is not shown on QScrollArea
On 21.02.07 14:33:49, Hadas Sandor wrote:
> Then I go through the QVector and elements to the QGridLayout:
> int Row = 0;
> pScrollLayout = new QGridLayout();
At this point you have a layout that is not associated with any widget
and has no parent.
> And I add the layout to the scroll area:
> ScrollArea.setWidget(pScrollLayout->widget());
See above, you don't have a widget associated with the layout, so
widget() will return 0.
What you want to do is something like
QWidget* w = new QWidget(ScrollArea)
pScrollLayout = new QGridLayout(w);
ScrollArea->setWidget(w);
Andreas
--
[ signature omitted ]