Resize layout and buttons contents

  • hello.
    I have a grid layout wit many buttons and this layout is in a docking window.
    I wish when i resize the window that the layout becomes small and the buttons in the layout become also more small

  • To do this thing, I think you should introduce your own @QPushButton@ derived custom widget.

    In constructor,

    • call @QWidget::setSizePolicy(QSizePolicy(QSizePolicy::Expanding, QSizePolicy::Expanding))@ to show it first time in a as best size as possible but fully expandable. (note: do not use QSizePolicy::Ignored. this will make button lost its best size).
    • call @QWidget::setMinimumSize(QSize(1,1))@ to be shrinkable.

    In overrided @virtual paintEvent(QPaintEvent* e)@,

    • get the best font size QFontMetricsF. search forum or google, you can find a example to get the best font size to fit a specific space.
    • draw the button text your own.

    That's it. If i were you , I'd not use text but use image which is easier to draw fully covered on widget area in this case.

Log in to reply

Looks like your connection to Qt Forum was lost, please wait while we try to reconnect.