Qt-interest Archive, May 2007
QStatusBar size
Message 1 in thread
I have one statusbar, which have some message fields on right side,
created as permanent widgets (one have coordinates in image, anothe
holds dimensions, etc ...)
StatusBar::StatusBar(QWidget *parent) : QStatusBar(parent) {
field1=new QLabel(" ",this);
addPermanentWidget(field1,0);
field2=new QLabel(" ",this);
addPermanentWidget(field2,0);
msgLabel=new QLabel(" ",this);
addWidget(msgLabel,8);
}
I have also one slot for each QLabel which relays the message, like
msgLabel->setText(theMessage);
Problem is, when the message is overly long, the label field will
grow, which causes the statusbar to grow and this causes the main
windows to grow. It is a bit like if you hover over long url link in
browser, the window will be enlarged to show entire link (and it will
be also its minimum size, so it can't be resized back to reasonable
size by user).
I tried to forbid the statusbar to change the size.
I tried adding size policy:
setSizePolicy(QSizePolicy::Preferred,QSizePolicy::Preferred);
to the statusbar and to the msgLabel
but that doesn't work
I tried adding resize event to my main window:
void MainWindow::resizeEvent(QResizeEvent *e) {
status->setMaximumWidth(e->size().width());
status->setMinimumWidth(2);
QMainWindow::resizeEvent(e);
}
This will prevent the statusbar from growing the main window,
unfortunately these two lines "status->..." break layout in some weird
way (menubar shrunk to 2 pixel height, toolbars shifted ...). Is there
something I have missed?
Is there any way to tell the statusbar that it may resize only if main
window is resized?
In QT documentation I noticed "The label resizes itself if
auto-resizing is enabled." written in several QLabel's methods,
however, I found no further mentions of QLabel's auto-resizing.
Martin Petricek
--
[ signature omitted ]
Message 2 in thread
Well, I have solved this in meantime. It was sufficient to add
status->setMinimumWidth(2);
to constructor of the main window and not use the resizeEvent at all.
This fixed the issue, the statusbar will never grow when long message
is in it, the message just get clipped, which is what I wanted ...
The docs says:
If minimumSize() is set, the minimum size hint will be ignored.
Probably the minimum size hint was size of the lengthy message and
internal layout was enlarging the satusbar and the main window.
Maybe the notice about QLayout that is at minimumSizeHint should be
also at minimumSize, didn't notice it first time and spend lot of time
trying to figure this out :)
Martin Petricek
On 5/19/07, BH <singularita@xxxxxxxxx> wrote:
> I have one statusbar, which have some message fields on right side,
> created as permanent widgets (one have coordinates in image, anothe
> holds dimensions, etc ...)
>
> StatusBar::StatusBar(QWidget *parent) : QStatusBar(parent) {
> field1=new QLabel(" ",this);
> addPermanentWidget(field1,0);
> field2=new QLabel(" ",this);
> addPermanentWidget(field2,0);
> msgLabel=new QLabel(" ",this);
> addWidget(msgLabel,8);
> }
>
> I have also one slot for each QLabel which relays the message, like
> msgLabel->setText(theMessage);
>
> Problem is, when the message is overly long, the label field will
> grow, which causes the statusbar to grow and this causes the main
> windows to grow. It is a bit like if you hover over long url link in
> browser, the window will be enlarged to show entire link (and it will
> be also its minimum size, so it can't be resized back to reasonable
> size by user).
>
> I tried to forbid the statusbar to change the size.
>
> I tried adding size policy:
> setSizePolicy(QSizePolicy::Preferred,QSizePolicy::Preferred);
> to the statusbar and to the msgLabel
> but that doesn't work
>
> I tried adding resize event to my main window:
> void MainWindow::resizeEvent(QResizeEvent *e) {
> status->setMaximumWidth(e->size().width());
> status->setMinimumWidth(2);
> QMainWindow::resizeEvent(e);
> }
>
> This will prevent the statusbar from growing the main window,
> unfortunately these two lines "status->..." break layout in some weird
> way (menubar shrunk to 2 pixel height, toolbars shifted ...). Is there
> something I have missed?
>
> Is there any way to tell the statusbar that it may resize only if main
> window is resized?
>
> In QT documentation I noticed "The label resizes itself if
> auto-resizing is enabled." written in several QLabel's methods,
> however, I found no further mentions of QLabel's auto-resizing.
>
> Martin Petricek
>
--
[ signature omitted ]