[Interest] QGridLayout does not update
preeteesh kakkar
preeteesh.kakkar at gmail.com
Tue Mar 19 15:40:05 CET 2013
Try calling gridlayout->update() and see if that helps?
On Tue, Mar 19, 2013 at 9:28 AM, Etienne Sandré-Chardonnal <
etienne.sandre at m4x.org> wrote:
> Dear all,
>
> I am encountering the following issue using QGridLayout in a widget.
>
> The QGridLayout is currently used for displaying labels along a grid with
> two columns, in a subclassed QWidget. This QWidget was set as the widget of
> a QSCrollArea, the QScrollArea is the content of a QDockWidget.
>
>
> 1) In the QWidget constructor, I create the QGridLayout and populate it
> with dummy labels for testing. This works:
>
> gridLayout = new QGridLayout(this);
> setLayout(gridLayout);
>
> for(int i=0;i<15;i++)
> {
> QLabel * nameWidget = new QLabel("Testing!!!!!!", this);
> gridLayout->addWidget(nameWidget, i, 0);
> QLabel * statusWidget = new QLabel("N/A", this);
> gridLayout->addWidget(statusWidget, i, 1);
> }
>
>
> This works as expected, especially the column size is adjusted to the
> QLabel widths
>
>
> 2) Then in a "setServerNames" slot of the QWidget, I do:
>
> QLayoutItem *child;
> while ((child = gridLayout->takeAt(0)) != 0) {
> delete child->widget();
> delete child;
> }
>
> if(serverList.size()==0)
> return;
>
>
> for(int i=0;i<serverList.size();i++)
> {
> QLabel * nameWidget = new QLabel(serverList[i], this);
> gridLayout->addWidget(nameWidget, i, 0);
> QLabel * statusWidget = new QLabel("N/A", this);
> gridLayout->addWidget(statusWidget, i, 1);
> }
>
>
>
>
>
> When the slot is called, the layout is not refreshed : the column width
> stays as it was adjusted in the constructor, so some of the QLabels are
> cropped, while there is still plenty of space on the right.
> Worse, if the layout is not populated in the constructor, then when the
> slot is called, nothing is displayed, likely because the layout is not
> refreshed, and sizes are null.
> I'm using Qt 4.8.3 under Windows
>
> Any idea?
>
> Thanks!
>
> Etienne
>
>
>
> _______________________________________________
> Interest mailing list
> Interest at qt-project.org
> http://lists.qt-project.org/mailman/listinfo/interest
>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.qt-project.org/pipermail/interest/attachments/20130319/63ecb2d9/attachment.html>
More information about the Interest
mailing list