Unsolved Incorrect header strings in Qtreeview
-
@Qt-Enthusiast said in Incorrect header strings in Qtreeview:
I am trying to implement a column drag functionality in which If I drag a column header from oldIndex to newVisIndex I should be able to change the order of the columns
QTreeView
already does that.#include <QApplication> #include <QTreeView> #include <QStandardItemModel> int main(int argc, char **argv) { QApplication app(argc, argv); QStandardItemModel baseModel; baseModel.insertRows(0, 3); baseModel.insertColumns(0, 4); QTreeView view; view.setModel(&baseModel); view.show(); return app.exec(); }
-
@VRonin said in Incorrect header strings in Qtreeview:
#include <QApplication>
#include <QTreeView>
#include <QStandardItemModel>
int main(int argc, char **argv) {
QApplication app(argc, argv);
QStandardItemModel baseModel;
baseModel.insertRows(0, 3);
baseModel.insertColumns(0, 4);
QTreeView view;
view.setModel(&baseModel);
view.show();
return app.exec();
}which part of code impliments column drag and I have QAbsractItem mode not QStandardItemModel
-
@Qt-Enthusiast said in Incorrect header strings in Qtreeview:
which part of code impliments column drag
None, that's the point. It comes for free with
QTreeView
.@Qt-Enthusiast said in Incorrect header strings in Qtreeview:
I have QAbsractItem mode not QStandardItemModel
The model never knows the column movement happened.
-
Also If I have to change the header list order in some backend API then what is to be done how to do that , I need a slot that tell header col order has changes
-
@Qt-Enthusiast said in Incorrect header strings in Qtreeview:
Also If I have to change the header list order in some backend API then what is to be done how to do that
You can use a proxy like KRearrangeColumnsProxyModel
-
is there any way I can stop inbuilt column drag functionality and impliment my own
-
view->headerView()->setSectionsMovable(false);
-
@VRonin said in Incorrect header strings in Qtreeview:
setSectionsMovable
I want to reimpliment my header drag can this we done -
void winBase::slotSectionMoved(int logicalIdx, int oldVisualIndex, int newVisualIndex) { vector<string> updateCols; for(int i =0 ; i < columnHeaderNames.size();i++) { QVariant var = p_TreeModel->headerData(i,Qt::Horizontal); QString colName = var.toString(); updateCols.push_back(colName.toStdString()); qDebug() << "\n I am here " << colName << " i =" << i; } setVisibleCols(updateCols); // this update backend column order which is python dataframes }
void winBase::reorder() 1884 for(int i = 0; i < _listOfVisibleCols.size();i++) 1885 getTreeModel()->setHeaderData(i,Qt::Horizontal,QString::fromStdString(_listOfVisibleCols[i])); 1886 1887 slotColumnChange(_listOfVisibleCols); } void WinBase::slotColumnyChange(vector<string>& visibleColList) { treeModel->showColumns(visibleColList); ----------------updates Python data frame }
-
What I am doing wrong
-
What's the link between
winBase::slotSectionMoved
andwinBase::reorder()
? -
updated the backend API
When I move th header , is there any way , I can update order of columns
-
I think I lost you in all the code.
In theory reimplementing
QAbstractItemModel::moveColumns
should be what you want (you may need to call it recursively though) -
@Qt-Enthusiast said in Incorrect header strings in Qtreeview:
When I drag the columns I want the upddate the column order list
-
Ok I tell my goal
When I move or drag the column headers, there is a backend python data frame which has column headers , I want to send the updated column header orders to the backend python layer . How do I do it , You can tell the code from scratch