user1627863
user1627863

Reputation: 13

Qt 4.8: Layout: Hide widgets if no more space available

My application window can be resized to zero-size. I do not want to restrict the minimum window size. There are several widgets (QLineEdits, QLabels, QPushButtons) layoutet by a HBoxLayout.

At first, all widgets in the HBoxLayout were resized without respecting their sizeHint when the window was very small. Then I used setFixedSize(sizeHint) on them. Now they do not get shrunk below their sizeHint, but instead they start overlapping when the window is very small.

What I want is what Thunderbird does (screenshots attached): It smoothly hides the widgets by moving them out of the window border. Their size is unchanged.

How can I achieve that with the Qt Layouting system?

my application: normal window
https://i.sstatic.net/WLgLy.png

my application: small window
https://i.sstatic.net/IIhhs.png

Thunderbird: normal window    
https://i.sstatic.net/AYJ83.png

Thunderbird: small window
https://i.sstatic.net/ZyQou.png

Upvotes: 1

Views: 445

Answers (2)

Eric Hulser
Eric Hulser

Reputation: 4022

  1. Put your widgets into a QScrollArea
  2. Set the vertical and horizontal scroll bar policy's to AlwaysOff
  3. Layout your Scroll area as you wish

Done & done

Upvotes: 1

HeyYO
HeyYO

Reputation: 2073

Probably that's not what you want but consider this: Put your all stuff in a widget (named just 'widget' here), do not put this 'widget' into any layout just leave it free and add this event function to your window class:

void MainWindow::resizeEvent(QResizeEvent *event){
   ui->widget->move(QPoint(event->size().width()-ui->widget->width()-20,ui->widget->y()));
   QMainWindow::resizeEvent(event);
}

it works!

Upvotes: 0

Related Questions