Results 1 to 2 of 2

Thread: QTableView Hidden Sections and Indexes

  1. #1
    Join Date
    Apr 2011
    Posts
    19
    Thanks
    3
    Thanked 4 Times in 2 Posts
    Qt products
    Platforms
    Unix/X11 Windows

    Default QTableView Hidden Sections and Indexes

    I am using a QTableView. In my view I have given the user the ablility to hide columns and unhide them through a context menu and also to move the columns. I also wanted to give the user the abliltiy to copy and paste between excel and my table view. The copy part I have down pasting is becoming a problem. In my case let say in excel I copy a 2x2 block of cells to the clipboard. I then select a cell in my table view that belongs to a column that has been moved and had a hidden column next to it. So from selecting that one cell I expect it to paste the 2x2 block on the clipboard. However I am getting confused in the tangle between switching back and forth from the logical index to the visual index and my problem is further complicated by the fact that the hidden columns are counted in the visual index. So instead of incrementing my column index by one I have to check if the next column is hidden or not and it just seems like to much I must be doing something wrong. Is there a way to get a visual index without the hidden columns in it. I am using PyQt. A sample of something that kind of works is below.
    getlistfromclipboard is returning a list of list which I am iterating through.
    Qt Code:
    1. sel = self.selectedIndexes()
    2.  
    3. lidx = sel[0]
    4. if len(sel) == 1:
    5. buf = self.getlistfromclipboard()
    6. hh = self.horizontalHeader()
    7. rz = sel[0].row()
    8. log_col = sel[0].column()
    9. vis_col = hh.visualIndex(log_col)
    10. for row_num, row in enumerate(buf):
    11. row_num = row_num + rz
    12. for col_num, value in enumerate(row):
    13. while True:
    14. lcol = hh.logicalIndex(col_num + vcz)
    15. if (self.horizontalHeader().isSectionHidden(lcol) or
    16. (col_num + vcz) <= self.model().columnCount()):
    17. print(col_num + vcz)
    18. col_num = col_num + 1
    19. else:
    20. idx = self.model().createIndex(row_num, lcol)
    21. break
    22. self.model().setData(idx, QtCore.QVariant(value))
    To copy to clipboard, switch view to plain text mode 

  2. #2
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,359
    Thanks
    3
    Thanked 5,015 Times in 4,792 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: QTableView Hidden Sections and Indexes

    Visual index is just the index of the column that takes into account reordering of columns. It does not carry any information about hidden state. Thus you need to take both visualIndex() and isSectionHidden() into consideration.
    Your biological and technological distinctiveness will be added to our own. Resistance is futile.

    Please ask Qt related questions on the forum and not using private messages or visitor messages.


Similar Threads

  1. after sorting get the indexes right
    By KillGabio in forum Newbie
    Replies: 8
    Last Post: 27th January 2012, 17:14
  2. Showing a Hidden QTableView Column
    By dchow in forum Qt Programming
    Replies: 1
    Last Post: 16th June 2011, 00:11
  3. problem with indexes
    By MarkoSan in forum Qt Programming
    Replies: 5
    Last Post: 10th December 2007, 14:55
  4. Getting indexes of selected items
    By gyre in forum Newbie
    Replies: 2
    Last Post: 20th November 2007, 19:23
  5. Replies: 4
    Last Post: 19th April 2007, 13:17

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.