reading data and storing from Qtreewidget
-
hi Qt community i need your help with Qtreewidget topic
here is the problem i want to read the coordinates to plot the graph by the tree i am not sure how to do theat i tried with item clicked signal but i am only able to select one coordinate point please tell how to do iti am attaching the part of the code i have tried please feel free to suggest a good approach to do what i am trying to do
void MainWindow::on_treeWidget_itemClicked(QTreeWidgetItem *item, int column)
{
QString point_x = item->text(column);
qDebug() << point_x;double x = point_x.toDouble(); qDebug() << x;
}
Thanks in advance
-
@123newuser your question is unclear
-
You need to know what you want to draw before attempting to actually draw it.
- do you want to draw all points from the tree widget?
- do you want to draw all points which are children of selected item?
- do you want to draw all points which are siblings of selected item?
once you answer this, you can start working on the algorithm. Typically this would involve getting data from your model - QTreeWidget is only visual representation of model data after all.
Then last step is to plot the points in some chart widget. Do you have some working solution here or are you looking for options?
-
@sierdzio my tree is looking like this
i want to select the x coordinate from parameter1 child and y from parameter 2 childafter selecting them and storing i am thinking of giving a push button which will initiate the new window /widget to plot the linegraph
i am very new to Qt started learning it less than a month back
please suggest a proper way to implement my problem -
@eyllanesc sorry for that
here is the question i have a tree which has all the plotting points i want to select the plotting points by clicking on them and proceed to plot the graphthe problem i am facing now is that i am only able to select single point
-
@123newuser https://doc.qt.io/qt-5/qabstractitemview.html#selectionMode-prop
https://doc.qt.io/qt-5/qabstractitemview.html#SelectionMode-enum
QAbstractItemView::ExtendedSelection -
OK, so you can select items with extended selection like @jsulm suggests. Then, when you click the button for plotting the data, you can get the
QModelIndex
es from selection. Then it's easy to get the data, you just calldata()
on your model, with properQModelIndex
and it will give you all you need.To plot the data, you can use QtCharts module.