Results 1 to 8 of 8

Thread: Usage of QTableView as gridview

  1. #1
    Join Date
    May 2010
    Posts
    46
    Thanks
    3
    Thanked 1 Time in 1 Post
    Qt products
    Qt4 Qt/Embedded
    Platforms
    Symbian S60

    Exclamation Usage of QTableView as gridview

    QTableView provides a row & column headers .. i.e it has a name for every row & every column. How to remove these names & convert it to a standard grid view ? The attached image show what I mean ...

    qtableview.JPG

  2. #2
    Join Date
    Jan 2006
    Location
    Germany
    Posts
    4,380
    Thanks
    19
    Thanked 1,005 Times in 913 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows Symbian S60
    Wiki edits
    5

    Default Re: Usage of QTableView as gridview

    Get the header via QTableView::horizontalHeader() and hide it. See also QTableView::verticalHeader().

  3. #3
    Join Date
    May 2010
    Posts
    46
    Thanks
    3
    Thanked 1 Time in 1 Post
    Qt products
    Qt4 Qt/Embedded
    Platforms
    Symbian S60

    Default Re: Usage of QTableView as gridview

    I would also like to set the row count & column count ...but in QTableView there does not seem to be any API for doing so .. how else should I customize the row & column count ?

  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: Usage of QTableView as gridview

    The view displays the data in the underlying mode, so the row/column count comes from there. You can hide columns or rows in the view: QTableView::setColumnHidden(). If you just want a table of x by y rows/columns that you can display values in then you can also use QTableWidget.

  5. #5
    Join Date
    May 2010
    Posts
    46
    Thanks
    3
    Thanked 1 Time in 1 Post
    Qt products
    Qt4 Qt/Embedded
    Platforms
    Symbian S60

    Exclamation Re: Usage of QTableView as gridview

    If I had say 20 items ( QStandardItems ) to the tableview, it just puts it into one vertical list ... why has the QGridView class been removed ?
    I plan to add custom items to the table view using custom model class later on ... but it should work with any type of items ... row/column hiding does not work ...

  6. #6
    Join Date
    Jan 2006
    Location
    Germany
    Posts
    4,380
    Thanks
    19
    Thanked 1,005 Times in 913 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows Symbian S60
    Wiki edits
    5

    Default Re: Usage of QTableView as gridview

    if you want a grid view have a look at QListView and its view modes and grid size!

  7. #7
    Join Date
    May 2010
    Posts
    46
    Thanks
    3
    Thanked 1 Time in 1 Post
    Qt products
    Qt4 Qt/Embedded
    Platforms
    Symbian S60

    Default Re: Usage of QTableView as gridview

    Thanks, the above suggestion worked ...

  8. #8
    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: Usage of QTableView as gridview

    Quote Originally Posted by ada10 View Post
    If I had say 20 items ( QStandardItems ) to the tableview, it just puts it into one vertical list ... why has the QGridView class been removed ?
    You add items to a model, not a view (QTableWidget just hides the model from you). If you add all the items in column 0 then that is what will be displayed by any view you attach to that model. Take a look at QStandardItemModel::setItem() for a way to set a cell other than column 0, or QStandardItemModel::insertRow() or insertColumn() (the ones that take a list of items) for ways to add whole rows/columns.
    I plan to add custom items to the table view using custom model class later on ... but it should work with any type of items ... row/column hiding does not work ...
    Yes it does.
    Qt Code:
    1. #include <QtGui>
    2.  
    3. int main(int argc, char *argv[])
    4. {
    5. QApplication app(argc, argv);
    6.  
    7. QStandardItemModel model(8, 8);
    8. for (int row = 0; row < 8; ++row) {
    9. for (int column = 0; column < 8; ++column) {
    10. QStandardItem *item = new QStandardItem(QString("%0, %1").arg(row).arg(column));
    11. model.setItem(row, column, item);
    12. }
    13. }
    14.  
    15. v.setModel(&model);
    16. v.setRowHidden(3, true);
    17. v.setColumnHidden(3, true);
    18. v.show();
    19. return app.exec();
    20. }
    To copy to clipboard, switch view to plain text mode 
    Attached Images Attached Images

Similar Threads

  1. QML usage
    By icek in forum Qt Programming
    Replies: 0
    Last Post: 5th August 2010, 17:02
  2. Very high CPU usage with QTableView and MVC
    By montylee in forum Qt Programming
    Replies: 7
    Last Post: 24th March 2009, 06:14
  3. QTableView Delegate Usage
    By rajeshs in forum Qt Programming
    Replies: 1
    Last Post: 14th April 2008, 07:03
  4. Replies: 1
    Last Post: 14th October 2007, 10:09
  5. Qt4 XML usage
    By kandalf in forum Qt Programming
    Replies: 1
    Last Post: 21st November 2006, 20:18

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.