1
votes

The main window of my application is a QWidget with a QGridLayout comprising several other widgets, including a QStatusBar.

I followed the Qt documentation http://doc.qt.io/qt-4.8/qstatusbar.html, so that my status bar is able to display:

  • a "normal message" (namely: "Ready"), by way of adding a QLabel to the status bar using QStatusBar::addWidget().
  • temporary messages (that temporarily hide the "normal message"), by calling QStatusBar::showMessage().

My problem is that when a temporary message is shown on or cleared off the status bar, then it apparently triggers QLayout::activate() (on the layout of my main window). This in turn possibly provokes a resizing of the other widgets in my window, and I do not want that to happen.

The curious (annoying) thing is that the status bar is actually not resized (as it should, it doesn't need to be resized), so I'm not sure why QStatusBar::showMessage() would ask the layout to resize anything.

Anyone knows a solution to this? Thanks in advance!

1
This is just a shot in the dark, but statusBar()->setSizePolicy(QSizePolicy::Ignored, QSizePolicy::Fixed); might keep the status bar from trying to mess with your layout too much. - Jeremy Friesner
I just tried your suggestion, unfortunately it's still the same :( - Seub
If QLayout::activate() causes other things to resize in spite of all widget sizes supposedly being the same, there's something horribly wrong. You should be able to call activate() on any layout without any effects at all, as many times as you wish - as long as everything is correct. Are you using any custom widgets? Please produce a minimal, self-contained, single-file test case. - Kuba hasn't forgotten Monica
@KubaOber: You're right, there's something unnatural about my layout. It doesn't "naturally" place the widgets where I want them, so I force my widgets to go where I want after any resizing (by doing setGeometry() on the widgets). It's probably a bad way to handle things but I couldn't come up with a better idea. I suppose I should create my own layout class inheriting QLayout, but that sounds like a lot of work. Things is, I'm happy with what I have for the moment, this status bar messages activating the layout are the only thing annoying me. Maybe I'll try to produce a minimal example. - Seub
@Seub The use of a layout and setGeometry is exclusive: you can do either one, but never both at the same time. Your code is broken and you must fix it first. "I should create my own layout class inheriting QLayout, but that sounds like a lot of work." The very reason that you've posted this question is that you're making life very hard for yourself already. What you've done so far is a bad hack and I'd never pass it in a code review. It will not work properly, it's not meant to, and you're breaking all sorts of invariants by doing things that way. - Kuba hasn't forgotten Monica

1 Answers

-1
votes

Use

QWidget::adjustSize()

To adjust parent widget to fit its content after showing or clearing off the message on the status bar