PDA

View Full Version : How to update layout after widget visibility change ?



phenoboy
10th September 2013, 07:31
When I hide one widget in the program the layout is not updated/resized until I manually resize the window with a mouse.

Is there a way to update/refresh layout after I hide widgets inside a layout ?

wagmare
10th September 2013, 07:59
look at
setSizeConstraint of Layout
setSizeConstraint ( SizeConstraint )

may be u need
setSizeConstraint(QLayout::SetFixedSize);

check the example
http://harmattan-dev.nokia.com/docs/library/html/qt4/dialogs-extension.html

wysota
10th September 2013, 08:20
When I hide one widget in the program the layout is not updated/resized until I manually resize the window with a mouse.

Is there a way to update/refresh layout after I hide widgets inside a layout ?

Show the code please.

phenoboy
10th September 2013, 09:41
Show the code please.

I think I narrowed down the code to this. MyLabel is inherited from QLabel. I want it to change size (to maximum space) when I resize the window. It looks like it is not resizing automatically after this resize event. Is there some method I'm missing here ?



void MyLabel::resizeEvent(QResizeEvent* ev)
{
int minPointSize=14;
const QSize& sz=ev->size();
const QFont& fnt=font();
QFont f=fnt;

qDebug() << "Resize event:" << sz << "pixelsize:" << f.pixelSize()
<< "." << f.pointSize();

f.setPointSize(sz.height()/2);

if (f.pointSize() < minPointSize) {
f.setPointSize(minPointSize);
}

setFont(f);

}

wysota
10th September 2013, 09:49
What exactly do you mean that it is not "resizing automatically"? A resizeEvent is triggered after a resize, not before a resize. If you get a resizeEvent then the widget has already been resized.

phenoboy
10th September 2013, 10:10
What exactly do you mean that it is not "resizing automatically"? A resizeEvent is triggered after a resize, not before a resize. If you get a resizeEvent then the widget has already been resized.

Some more code.. The main widget contains three components (in different layouts). One is gauge, lcdnumber and a label. In this function I'm either showing gauge and hiding lcd or hiding gauge and showing lcd. Also I'm rearranging widgets because I want text label to be first. I was thinking that when layout is changed -> resize event is triggered and label is updated.

Now what happens when switching to condition noGauge==false is that gauge is hidden and font is resized correctly BUT the window size doesn't change and text that label contains is not shown fully . Only when I resize main window then label gets resized correctly and it shows full text



void switchView() {
if (noGauge) {
m_gauge->setVisible(true);
ui->lcdNumber->setHidden(true);
noGauge=false;
} else {
m_gauge->setVisible(false);
ui->lcdNumber->setVisible(true);
ui->layoutLCDTop->removeWidget(label);
ui->layoutLCDTop->addWidget(label);
ui->layoutLCDTop->addWidget(ui->lcdNumber);

noGauge=true;
}
}

wysota
10th September 2013, 10:27
Changing the widget position does not cause a resize. If you want to update widget contents, call update() on it and a paint event will be scheduled.