QtableView setSortingEnabled forcing sortByColumn()
-
@mapuna
I'm afraid I'm not the right person to ask really:-
I don't use QtCreator, so I don't know.
-
I'm not sure just what you mean. You cannot just dynamically/run-time cast an object to another type/derived type because "you feel like it", when the object was constructed it must actually have been of the type you are casting to. So your
QTableView
must actually have been created as aDerivedTableView
(including if that's done in QtCreator). But then wherever you can use aQTableView
you can use yourDerivedTableView
, e.g. forsetModel()
call. -
No example from me. I don't even use C++, I use Python! :(
But I'm sure someone else can clarify the above.....
-
-
Hi,
- http://doc.qt.io/qt-5/designer-using-custom-widgets.html
- You don't need to, just call
setModel
like you are doing currently - Do you mean something like:
MyView *view = new MyView; ui->layout_name->add(view);
?
-
You could set default sorting column to -1 by QHeaderView::setSortIndicator like this
yourTableView->horizontalHeader()->setSortIndicator(-1, Qt::AscendingOrder);
before running
yourTableView->setSortingEnabled(true);
because QTableView::setSortingEnabled uses QHeaderView::sortIndicatorOrder and QHeaderView::sortIndicatorSection to identify by which column should model be sorted.
Note that documentation of QHeaderView::setSortIndicator tells that not all models support setting sort column to -1 and may even crash in this case.