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. Form setting preferred size

Form setting preferred size

Scheduled Pinned Locked Moved Unsolved General and Desktop
5 Posts 4 Posters 681 Views 2 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.
  • SPlattenS Offline
    SPlattenS Offline
    SPlatten
    wrote on last edited by
    #1

    I have a form / dialog derived from QWidget, the form contains a QTableView and under this is a QScrollArea which contains tabs and pages. I wrote this quite a while ago and now I've been asked to set adjust the default size of the window so it defaults to the required width to show all the columns in the QTableView.

    I was looking at setting the size policy and setting a preferred width, what are the related methods called for setting the preferred width?

    Kind Regards,
    Sy

    Pl45m4P 1 Reply Last reply
    0
    • SPlattenS SPlatten

      I have a form / dialog derived from QWidget, the form contains a QTableView and under this is a QScrollArea which contains tabs and pages. I wrote this quite a while ago and now I've been asked to set adjust the default size of the window so it defaults to the required width to show all the columns in the QTableView.

      I was looking at setting the size policy and setting a preferred width, what are the related methods called for setting the preferred width?

      Pl45m4P Offline
      Pl45m4P Offline
      Pl45m4
      wrote on last edited by
      #2

      @SPlatten said in Form setting preferred size:

      show all the columns in the QTableView.

      • https://doc.qt.io/qt-5/qtableview.html#resizeColumnsToContents
      • https://doc.qt.io/qt-5/qheaderview.html#ResizeMode-enum

      If debugging is the process of removing software bugs, then programming must be the process of putting them in.

      ~E. W. Dijkstra

      SPlattenS 1 Reply Last reply
      1
      • Pl45m4P Pl45m4

        @SPlatten said in Form setting preferred size:

        show all the columns in the QTableView.

        • https://doc.qt.io/qt-5/qtableview.html#resizeColumnsToContents
        • https://doc.qt.io/qt-5/qheaderview.html#ResizeMode-enum
        SPlattenS Offline
        SPlattenS Offline
        SPlatten
        wrote on last edited by SPlatten
        #3

        @Pl45m4 said in Form setting preferred size:

        https://doc.qt.io/qt-5/qheaderview.html#ResizeMode-enum

        That works fine for adjusting the columns to fit the content, thank you, how can I get the form to adjust to accommodate the QTableView so I don't have to scroll horizontally?

        Kind Regards,
        Sy

        1 Reply Last reply
        0
        • B Offline
          B Offline
          Bob64
          wrote on last edited by
          #4

          It's been a long while since I used widgets, but could you do this by implementing sizeHint, making use of contentsRect?

          1 Reply Last reply
          1
          • AxelViennaA Offline
            AxelViennaA Offline
            AxelVienna
            wrote on last edited by
            #5

            As Bob64 said, setSizeHint(const QSize &) is the way to define a widget's preferred size. A widget's runtime size is also depends the widget's size policy. If the widget is held by a layout, the layout type and (if existing) other widgets and their sizes are also considered. This is why setting a size hint does not necessarily lead to predictable column sizes of your list view.

            In case you want that, you can set the column sizes directly by setColumnWidth(int column, int width). A user-friendly way to remember widget sizes for the next session is to store them in a QSettings object, which you read in your constructor and update in your destructor.

            C++ and Python walk into a bar. C++ reuses the first glass.

            1 Reply Last reply
            1

            • Login

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