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
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
Get the header via QTableView::horizontalHeader() and hide it. See also QTableView::verticalHeader().
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 ?
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.
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 ...
if you want a grid view have a look at QListView and its view modes and grid size!
Thanks, the above suggestion worked ...
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.
Yes it does.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 ...
Qt Code:
#include <QtGui> int main(int argc, char *argv[]) { for (int row = 0; row < 8; ++row) { for (int column = 0; column < 8; ++column) { model.setItem(row, column, item); } } QTableView v; v.setModel(&model); v.setRowHidden(3, true); v.setColumnHidden(3, true); v.show(); return app.exec(); }To copy to clipboard, switch view to plain text mode
Bookmarks