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. Sizing a window so that a contained QTableWidget fits without scroll bars
QtWS25 Last Chance

Sizing a window so that a contained QTableWidget fits without scroll bars

Scheduled Pinned Locked Moved General and Desktop
4 Posts 3 Posters 1.2k Views
  • 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.
  • S Offline
    S Offline
    sipos
    wrote on last edited by
    #1

    I have a window with a QTableWidget inside it and, I would like to set the window geometry such that the QTableWidget fits inside the window without having horizontal scroll bars. I've tried searching for info on how to do this but, I've not found anything (the abundance of questions about resizing the columns/rows of the QTableWidget doesn't help). If anyone can tell me how to do this, I'd be very grateful.

    1 Reply Last reply
    0
    • SGaistS Offline
      SGaistS Offline
      SGaist
      Lifetime Qt Champion
      wrote on last edited by
      #2

      Hi,

      If you know the ideal size of your QTableWidget, you would use setFixeWidth

      Hop it helps

      Interested in AI ? www.idiap.ch
      Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

      S 1 Reply Last reply
      0
      • SGaistS SGaist

        Hi,

        If you know the ideal size of your QTableWidget, you would use setFixeWidth

        Hop it helps

        S Offline
        S Offline
        sipos
        wrote on last edited by sipos
        #3

        @SGaist I'd like to determine the size based on calling resizeColumnsToContents with the column headers set so that it fits the headers. I guess that this size will depend on platform.

        Edit to clarify: I'd like to set the column headers, call resizeColumnsToContents() on the QTableWidget and then set the window size to be just the right size to contain it without horizontal scrollbars.

        1 Reply Last reply
        0
        • Chris KawaC Online
          Chris KawaC Online
          Chris Kawa
          Lifetime Qt Champion
          wrote on last edited by
          #4

          Since QTableWidget is a subclass of QAbstractScrollArea you could get the size you need from viewportSizeHint() or with viewport()->size().

          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