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. How to set the preferred width when create a widget?
Forum Updated to NodeBB v4.3 + New Features

How to set the preferred width when create a widget?

Scheduled Pinned Locked Moved General and Desktop
2 Posts 2 Posters 4.2k 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.
  • O Offline
    O Offline
    opengpu
    wrote on 8 Dec 2014, 13:24 last edited by
    #1

    i just found the API to set minWidth/maxWidth. but i just want to set the width when the width is created...
    eg. i add a listbox or a tablewidget in the QDockWidget.

    1 Reply Last reply
    0
    • S Offline
      S Offline
      sierdzio
      Moderators
      wrote on 8 Dec 2014, 13:34 last edited by
      #2

      I am not sure I understand you well. So I'll post some general info and maybe you will find something useful in it;

      The preferred way of UI creation in QtWidgets is to use layouts. Layouts are responsible for correct positioning and sizing of all their widgets - there is no need to set any sizes by hand

      You can modify how a widget behaves in a widget by setting it's SizePolicy, min/ max size. You can also use Spacers to push widgets in layouts

      If you really want to change the size by hand, you can use setGeometry(), resize() or setFixedSize() methods

      If you want to know a nice "default" size for a widget, just use the sizeHint():

      @
      widget.setSize(widget.sizeHint());
      @

      (Z(:^

      1 Reply Last reply
      0

      1/2

      8 Dec 2014, 13:24

      • Login

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