Results 1 to 7 of 7

Thread: QTableWidget row insertion and set width of each column?

Hybrid View

Previous Post Previous Post   Next Post Next Post
  1. #1
    Join Date
    Mar 2006
    Posts
    47
    Thanks
    2
    Qt products
    Qt3 Qt4
    Platforms
    MacOS X Unix/X11

    Default Re: QTableWidget row insertion and set width of each column?

    Hi,
    I read the following functions but can't get how to set width of each column in QTreeWidget through QT Designer and through coding.

    to access headers:
    QTableView::horizontalHeader()
    QTableView::verticalHeader()

    to resize:
    QHeaderView::resizeSection()
    QHeaderView::setStretchLastSection()
    QHeaderView::setResizeMode()
    ...

    Please give some code example to set the width of QTreeWidget Column.

    Thanks and Regards

  2. #2
    Join Date
    Feb 2006
    Location
    Oslo, Norway
    Posts
    6,264
    Thanks
    36
    Thanked 1,519 Times in 1,389 Posts
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11 Windows Symbian S60 Maemo/MeeGo

    Default Re: QTableWidget row insertion and set width of each column?

    I thought it was QTableWidget..

    Qt Code:
    1. #include <QHeaderView>
    2. QTreeWidget* treeWidget = ...;
    3. treeWidget->header()->resizeSection(0, 20); // column 0, width 20
    4.  
    5. QTableWidget* tableWidget = ...;
    6. tableWidget->horizontalHeader()->resizeSection(1, 50); // column 1, width 50
    7. tableWidget->verticalHeader()->resizeSection(2, 15); // row 2, height 15
    To copy to clipboard, switch view to plain text mode 
    J-P Nurmi

  3. #3
    Join Date
    Mar 2006
    Posts
    47
    Thanks
    2
    Qt products
    Qt3 Qt4
    Platforms
    MacOS X Unix/X11

    Default Re: QTableWidget row insertion and set width of each column?

    Hi,
    First of all sorry , you are right, it was QTableWidget. I had to set width of Each column of QTable Widget.
    I also have requirement to delete all rows created through following lines:-
    row = tableWidget->rowCount(); // current row count
    tableWidget->setRowCount(row+1); // add one row
    I am able to clear the whole QTableWidget but how i can delete all the rows created through setRowCount(row+1).


    Thanks and Regards

  4. #4
    Join Date
    Sep 2006
    Posts
    38
    Thanks
    5
    Thanked 3 Times in 2 Posts
    Qt products
    Qt4 Qt5
    Platforms
    Windows

    Default Re: QTableWidget row insertion and set width of each column?

    You can always use QTableView::setColumnWidth() and call this both when your widget class is initialized and/or after your data loads.

    For removing the rows, tableWidget->removeRow(row+1) ??

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Digia, Qt and their respective logos are trademarks of Digia Plc in Finland and/or other countries worldwide.