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 ?
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 ?
look at
setSizeConstraint of Layout
setSizeConstraint ( SizeConstraint )
may be u need
setSizeConstraint(QLayout::SetFixedSize);
check the example
http://harmattan-dev.nokia.com/docs/...extension.html
"Behind every great fortune lies a crime" - Balzac
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 ?
Qt Code:
{ 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); }To copy to clipboard, switch view to plain text mode
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
Qt Code:
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; } }To copy to clipboard, switch view to plain text mode
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.
phenoboy (10th September 2013)
Bookmarks