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 of QTableView to have no scrollbars
Forum Updated to NodeBB v4.3 + New Features

Resize of QTableView to have no scrollbars

Scheduled Pinned Locked Moved General and Desktop
5 Posts 3 Posters 12.4k 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.
  • R Offline
    R Offline
    rubikon
    wrote on last edited by
    #1

    Hello.

    I have a QTableView on my ui with some columns and rows.

    What I would like to achieve is that the TableView resizes to a size that equates the content so that no scrollbars are needed. I hope it's clear what I mean :-)

    I have experimented with sizepolicy but with no success.

    1 Reply Last reply
    0
    • JeroentjehomeJ Offline
      JeroentjehomeJ Offline
      Jeroentjehome
      wrote on last edited by
      #2

      Hi there,
      If it is just that the window the TableView is in be resize, you could set the size of that window. If you don't want the window in which your tableView is display be resized you might want to give the model the notification that it needs to resize its contains. the TableView should have a sizechanged signal, connect that to a slot in the model that calculates the new size per socket/column (e.g. set a smaller / larger font). Then using this value in the model to refresh the tableView (reset or emit dataChanged).
      Remember that the tableView isn't responsible for the data that is presented, only to handle the view if needed (e.g. scrollbars). It will get all parameters from the underlying model.
      happy coding!

      Greetz, Jeroen

      1 Reply Last reply
      0
      • L Offline
        L Offline
        lgeyer
        wrote on last edited by
        #3

        See "QTableView::resizeColumnsToContents()":http://qt-project.org/doc/qt-4.8/qtableview.html#resizeColumnsToContents and "QHeaderView::ResizeMode":http://qt-project.org/doc/qt-4.8/qheaderview.html#ResizeMode-enum.

        1 Reply Last reply
        0
        • JeroentjehomeJ Offline
          JeroentjehomeJ Offline
          Jeroentjehome
          wrote on last edited by
          #4

          Hi Lukas,
          The resizeColumnsToContents will give the TableView scrollbars if the Table is bigger then the size of the view. Think that he want's to avoid the scrollbar by making the text in the table bigger and smaller to fit in the View.
          If the text runs out of the columns as Lukas suggest is the way to go!
          greetz

          Greetz, Jeroen

          1 Reply Last reply
          0
          • L Offline
            L Offline
            lgeyer
            wrote on last edited by
            #5

            [quote author="Jeroentje@home" date="1346847816"]The resizeColumnsToContents will give the TableView scrollbars if the Table is bigger then the size of the view.[/quote]It indeed does, but it allows you to set the preferred width then.
            @
            view.resizeColumnToContents();

            int width = (view.model()->columnCount() - 1) + view.verticalHeader()->width();
            for(int column = 0; column < view.model()->columnCount(); column++)
            width = width + view.columnWidth(column);
            view.setMinimumWidth(width);
            @

            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