Results 1 to 6 of 6

Thread: QTableView how to move columns with code

  1. #1
    Join Date
    May 2008
    Location
    Italy
    Posts
    4
    Thanks
    1
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Question QTableView how to move columns with code

    Hi, I want to rearrange some columns of a QTableView after setting the QTableModel. I want to exchange column 1 with 2. How I can do that?
    Thanks

  2. #2
    Join Date
    Aug 2008
    Location
    Ukraine, Krivoy Rog
    Posts
    1,963
    Thanked 370 Times in 336 Posts
    Qt products
    Qt3 Qt4 Qt5
    Platforms
    MacOS X Unix/X11 Windows

    Default Re: QTableView how to move columns with code

    have a look at QHeaderView::swapSections.
    Qt Assistant -- rocks!
    please, use tags [CODE] & [/CODE].

  3. The following user says thank you to spirit for this useful post:

    Marco (5th May 2009)

  4. #3
    Join Date
    May 2008
    Location
    Italy
    Posts
    4
    Thanks
    1
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Thumbs up Re: QTableView how to move columns with code

    Thank you!

    Qt Code:
    1. QHeaderView *headerView = tableView->horizontalHeader();
    2. headerView->swapSections(2, 1);
    To copy to clipboard, switch view to plain text mode 

  5. #4
    Join Date
    Oct 2006
    Location
    New Delhi, India
    Posts
    2,467
    Thanks
    8
    Thanked 334 Times in 317 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: QTableView how to move columns with code

    Also have a look at QHeaderView::moveSection

  6. #5
    Join Date
    Feb 2012
    Posts
    3
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: QTableView how to move columns with code

    QxTableView::QxTableView(QWidget *parent)
    : QTableView(parent)


    void QxTableView::moveSection(int from, int to)
    {
    verticalHeader()->moveSection(from, to);
    }

    void QxTableView::swapSections(int first, int second)
    {
    verticalHeader()->swapSections(first , second);
    }

  7. #6
    Join Date
    Mar 2016
    Posts
    1
    Qt products
    Qt4 Qt5
    Platforms
    Windows

    Default Re: QTableView how to move columns with code

    Quote Originally Posted by Marco View Post
    Thank you!

    Qt Code:
    1. QHeaderView *headerView = tableView->horizontalHeader();
    2. headerView->swapSections(2, 1);
    To copy to clipboard, switch view to plain text mode 
    Thank you.. Working AS is..

Similar Threads

  1. updating QTableView with new qsl columns
    By sylvainb in forum Qt Programming
    Replies: 2
    Last Post: 28th January 2009, 21:51
  2. How to display selected columns in QTableView widget.
    By kaushal_gaurav in forum Qt Programming
    Replies: 2
    Last Post: 8th August 2008, 09:30
  3. Different delegates to different Columns of QTableView.
    By kaushal_gaurav in forum Qt Programming
    Replies: 4
    Last Post: 6th August 2008, 10:17
  4. Ensure columns in qtableview uses all available space
    By oysteinpettersen in forum Qt Programming
    Replies: 2
    Last Post: 10th January 2008, 12:28
  5. how to move between columns in tree view?
    By Scott Shiff in forum Qt Programming
    Replies: 1
    Last Post: 30th January 2007, 09:01

Tags for this Thread

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.