Results 1 to 4 of 4

Thread: Clear QTableView of Hidden columns

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

    Default Clear QTableView of Hidden columns

    I have an excel like spread sheet that I am showing some test date in and I am using a QTableView in conjunction with a model. The user is allowed to both hide and move columns of the data. I want to be able to load data from a file. Everything works fine except the TableView seems to be holding onto which columns were hidden even after the model is reset.

    My model has a changeDataSet function that is like this
    Qt Code:
    1. def changeDataSet(self, dataset)
    2.  
    3. self.beginResetModel()
    4. self.dataset = dataset
    5. self.endResetModel()
    To copy to clipboard, switch view to plain text mode 

    This works fine the right number of columns and rows show up. All the data is in the right spot but the hidden columns seem to persist. Is there any way to reset the QTableView or do I need to go through and unhide all the hidden columns before I invalidate the model. If you couldn't tell from the Code block I am using PyQt and my data is coming from a Pickle file which is how I have a entire dataset class to just plug back in.

  2. #2
    Join Date
    Mar 2009
    Location
    Brisbane, Australia
    Posts
    7,729
    Thanks
    13
    Thanked 1,610 Times in 1,537 Posts
    Qt products
    Qt4 Qt5
    Platforms
    Unix/X11 Windows
    Wiki edits
    17

    Default Re: Clear QTableView of Hidden columns

    Just iterate over the columns of the new model and showColumn() the columns in a slot attached to the modelReset() signal.

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

    Default Re: Clear QTableView of Hidden columns

    Yeah that is the solution I came to as well in fact I already had a function in the view for unhiding all the columns. Although connecting to the modelReset signal I hadn't thought of. It just seemed like there should have been a more inclusive solution like a reset function or something. Additionally I was just concerned that there may be other things in the view that might not be resetting properly and that I just haven't noticed them yet.

  4. #4
    Join Date
    Mar 2009
    Location
    Brisbane, Australia
    Posts
    7,729
    Thanks
    13
    Thanked 1,610 Times in 1,537 Posts
    Qt products
    Qt4 Qt5
    Platforms
    Unix/X11 Windows
    Wiki edits
    17

    Default Re: Clear QTableView of Hidden columns

    Changing data in the model should not automatically change the state of the view. The view has no idea of the meaning of the data in the model or how that might have changed. In most cases you do not change the entire meaning of the underlying model only its content. I think it would be downright annoying if, every time you caused a QSqlQueryModel to requery a growing table, the view reordered, unhid and unsorted rows/columns when it is the same data being presented.

Similar Threads

  1. QTableView Hidden Sections and Indexes
    By mechsin in forum Newbie
    Replies: 1
    Last Post: 15th July 2012, 17:49
  2. Showing a Hidden QTableView Column
    By dchow in forum Qt Programming
    Replies: 1
    Last Post: 16th June 2011, 00:11
  3. how to clear selection in the qtableview
    By wenn32 in forum Newbie
    Replies: 1
    Last Post: 6th May 2011, 18:45
  4. Clear contents of a QTableView cell before repainting
    By aspidites in forum Qt Programming
    Replies: 2
    Last Post: 21st April 2009, 16:07
  5. updating QTableView with new qsl columns
    By sylvainb in forum Qt Programming
    Replies: 2
    Last Post: 28th January 2009, 20:51

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