Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. Resize layout and buttons contents
Qt 6.11 is out! See what's new in the release blog

Resize layout and buttons contents

Scheduled Pinned Locked Moved General and Desktop
2 Posts 2 Posters 2.9k Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • G Offline
    G Offline
    giuseppe500
    wrote on last edited by
    #1

    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

    1 Reply Last reply
    0
    • J Offline
      J Offline
      joonhwan
      wrote on last edited by
      #2

      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.

      joonhwan at gmail dot com

      1 Reply Last reply
      0

      • Login

      • Login or register to search.
      • First post
        Last post
      0
      • Categories
      • Recent
      • Tags
      • Popular
      • Users
      • Groups
      • Search
      • Get Qt Extensions
      • Unsolved