Results 1 to 5 of 5

Thread: Not showing all of model columns in the view

  1. #1
    Join Date
    Feb 2009
    Posts
    11
    Qt products
    Platforms
    Unix/X11 Windows
    Thanks
    4

    Default Not showing all of model columns in the view

    It's my first post here, so be gentle if you think my question is ignorant. I'm new to the model/view concept.
    I've got a 8-column model and I want my view just to represent SOME of its columns not all of them. In addition, these columns are not necessarily adjacent.
    How should I do that? Shall I subclass QTableView and change its behavior? Shall I modify my model? I don't think it's got anything to do with my delegate.
    Last edited by nimaweb; 7th August 2009 at 21:38.

  2. #2
    Join Date
    Jul 2009
    Location
    Enschede, Netherlands
    Posts
    462
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows
    Thanked 69 Times in 67 Posts

    Default Re: Not showing all of model columns in the view

    The best way to achieve that is to create a QSortFilterProxyModel. You don't have to change the behaviour of the view, you just have to filter out a bit of data.
    Horse sense is the thing that keeps horses from betting on people. --W.C. Fields

    Ask Smart Questions

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

    nimaweb (7th August 2009)

  4. #3
    Join Date
    Oct 2008
    Posts
    4
    Qt products
    Qt4
    Platforms
    Windows
    Thanked 1 Time in 1 Post

    Default Re: Not showing all of model columns in the view

    Hi,

    Quick answer. If you want remove some columns just.
    Qt Code:
    1. ui.ClientTableView->setColumnHidden(4,true);
    2. ui.ClientTableView->setColumnHidden(5,true);
    3. ui.ClientTableView->setColumnHidden(6,true);
    To copy to clipboard, switch view to plain text mode 
    And if you want to set custom headers
    Qt Code:
    1. clientsmodel->setHeaderData(20, Qt::Horizontal, tr("Deadline"));
    2. clientsmodel->setHeaderData(21, Qt::Horizontal, tr("Finished"));
    3. clientsmodel->setHeaderData(22, Qt::Horizontal, tr("Budget"));
    To copy to clipboard, switch view to plain text mode 

    All numbers in examples are column number.

  5. The following user says thank you to remdex for this useful post:

    nimaweb (7th August 2009)

  6. #4
    Join Date
    Feb 2009
    Posts
    11
    Qt products
    Platforms
    Unix/X11 Windows
    Thanks
    4

    Default Re: Not showing all of model columns in the view

    Problemo Solved
    Thanks, but do you think if I could place the columns in the view in order other than the corresponding ones in the model (or another view which has the same model)?
    Last edited by nimaweb; 7th August 2009 at 21:45.

  7. #5
    Join Date
    Feb 2009
    Posts
    11
    Qt products
    Platforms
    Unix/X11 Windows
    Thanks
    4

    Default Re: Not showing all of model columns in the view

    Quote Originally Posted by nimaweb View Post
    Problemo Solved
    Thanks, but do you think if I could place the columns in the view in order other than the corresponding ones in the model (or another view which has the same model)?
    I think I should do it like this:
    Qt Code:
    1. personnelView.horizontalHeader().moveSection(1,4)
    To copy to clipboard, switch view to plain text mode 
    ^ using PyQt

Similar Threads

  1. hierarchical model in a flat view
    By gniking in forum Qt Programming
    Replies: 4
    Last Post: 10th November 2009, 21:17
  2. Model / View - Design Question
    By antarctic in forum Qt Programming
    Replies: 8
    Last Post: 8th June 2009, 08:39
  3. Model, View and Proxy
    By No-Nonsense in forum Qt Programming
    Replies: 2
    Last Post: 21st November 2006, 09:50
  4. Model - View Programming doubt.
    By munna in forum Qt Programming
    Replies: 4
    Last Post: 28th April 2006, 14:01
  5. Replies: 6
    Last Post: 20th April 2006, 11:23

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.