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. QTableWidget adjust column and row size
Qt 6.11 is out! See what's new in the release blog

QTableWidget adjust column and row size

Scheduled Pinned Locked Moved General and Desktop
3 Posts 3 Posters 25.1k 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.
  • ? Offline
    ? Offline
    A Former User
    wrote on last edited by
    #1

    Hi! How can I adjust column width in QTableWidget as long as I resize the window, that holds QTableWidget? I need width of each coloumn and height of each row be resized when I resize the window, how can I achieve this?

    1 Reply Last reply
    0
    • ? Offline
      ? Offline
      A Former User
      wrote on last edited by
      #2

      You can set the headers resize mode to be "QHeaderView::Stretch":http://doc.qt.nokia.com/latest/qheaderview.html#ResizeMode-enum, then the columns and rows will resize when you resize the widget. Does doing so solve your problem?

      For example:
      @
      #include <QtGui>
      class TableWidget : public QTableWidget
      {
      Q_OBJECT
      public:
      TableWidget()
      {
      setRowCount(10);
      setColumnCount(5);
      QTableWidgetItem *newItem = new QTableWidgetItem("An item");
      setItem(0,0, newItem);
      horizontalHeader()->setResizeMode(QHeaderView::Stretch);
      verticalHeader()->setResizeMode(QHeaderView::Stretch);
      }
      };

      #include "main.moc"
      int main(int argc, char** argv)
      {
      QApplication app(argc, argv);
      TableWidget window;
      window.resize(400,400);
      window.show();
      return app.exec();

      }

      @

      1 Reply Last reply
      0
      • H Offline
        H Offline
        Hareen Laks
        wrote on last edited by
        #3

        sigrid,

        Thanks for your reply!

        It is working perfectly.

        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