Results 1 to 5 of 5

Thread: Renumbering Row Headers of QHeaderView

Hybrid View

Previous Post Previous Post   Next Post Next Post
  1. #1
    Join Date
    Aug 2006
    Location
    Madison, WI USA
    Posts
    153
    Qt products
    Qt4
    Platforms
    Windows
    Thanks
    35
    Thanked 1 Time in 1 Post

    Default Re: Renumbering Row Headers of QHeaderView

    Thanks for the quick reply.

    Using QTableView is currently not an option because of time restraints. After the release of the product, we will try to convert all our QTableWidget code to QTableView for subsequent releases.

    We may have to leave this feature out of this release.

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

    Default Re: Renumbering Row Headers of QHeaderView

    You could connect to signal QHeaderView::sectionMoved() and rename headers every time a section movement occurs. Just make sure you create and set header items.

    Qt Code:
    1. // it is important to create and set header items
    2. // otherwise horizontalHeaderItem(int) and verticalHeaderItem(int) will always return 0
    3. for (int r = 0; r < rowCount(); ++r)
    4. {
    5. QTableWidgetItem* item = new QTableWidgetItem(QString::number(r));
    6. setVerticalHeaderItem(r, item);
    7. }
    8.  
    9. for (int c = 0; c < columnCount(); ++c)
    10. {
    11. QTableWidgetItem* item = new QTableWidgetItem(QString::number(c));
    12. setHorizontalHeaderItem(c, item);
    13. }
    14.  
    15. connect(horizontalHeader(), SIGNAL(sectionMoved(int, int, int)), SLOT(renameHeaders()));
    16. connect(verticalHeader(), SIGNAL(sectionMoved(int, int, int)), SLOT(renameHeaders()));
    To copy to clipboard, switch view to plain text mode 

    Qt Code:
    1. // the slot doing the renaming
    2. void TableWidget::renameHeaders()
    3. {
    4. // "convert" logical indexes to visual indexes
    5. for (int r = 0; r < rowCount(); ++r)
    6. verticalHeaderItem(r)->setText(QString::number(verticalHeader()->visualIndex(r)));
    7.  
    8. for (int c = 0; c < columnCount(); ++c)
    9. horizontalHeaderItem(c)->setText(QString::number(horizontalHeader()->visualIndex(c)));
    10. }
    To copy to clipboard, switch view to plain text mode 
    J-P Nurmi

  3. #3
    Join Date
    Aug 2006
    Location
    Madison, WI USA
    Posts
    153
    Qt products
    Qt4
    Platforms
    Windows
    Thanks
    35
    Thanked 1 Time in 1 Post

    Default Re: Renumbering Row Headers of QHeaderView

    Thanks, jpn, this looks like a workable solution for my circumstances.

Similar Threads

  1. QTableView : headers disappear
    By xavier in forum Qt Programming
    Replies: 2
    Last Post: 8th May 2006, 16:57
  2. QMake / headers / lot of files
    By jcr in forum Qt Programming
    Replies: 7
    Last Post: 10th January 2006, 12:06

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
  •  
Qt is a trademark of The Qt Company.