Qt Forum

    • Login
    • Search
    • Categories
    • Recent
    • Tags
    • Popular
    • Users
    • Groups
    • Search
    • Unsolved

    Update: Forum Guidelines & Code of Conduct

    How to set the preferred width when create a widget?

    General and Desktop
    2
    2
    2805
    Loading More Posts
    • 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
      opengpu last edited by

      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 Reply Quote 0
      • sierdzio
        sierdzio Moderators last edited by

        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 Reply Quote 0
        • First post
          Last post