Page 1 of 1

Some questions about qcustomplot

Posted: Sun Apr 16, 2017 11:18 am
by snfge
Hi
I change the code like the follow, it can show the graph, but it can't zoom, why? and I want get the point when I click the graph, how can I do it ? And another question is if I use the function, I hope it can close the graph last time show, how can I do it?
ccHistogramWindowDlg* hDlg = new ccHistogramWindowDlg(parent);
ccHistogramWindow* histogram = hDlg->window();
histogram->addGraph();
histogram->graph(0)->setData(x, y);
histogram->graph(0)->setPen((QColor(255, 10, 0)));
if (XorY == 1)
{
histogram->xAxis->setLabel("X");
}
else
{
histogram->xAxis->setLabel("Y");
}
//histogram->xAxis->setLabel("X");
histogram->yAxis->setLabel("Z");
histogram->xAxis->setRange(x1, x2);
histogram->yAxis->setRange(y1, y2);
histogram->setTitle("daoyun");
histogram->replot();
histogram->setInteractions(QCP::iRangeDrag | QCP::iRangeZoom);
hDlg->show();
histogram->refresh();
return true;

Re: Some questions about qcustomplot

Posted: Mon Apr 17, 2017 3:52 pm
by daniel
The histogram dialog has no zoom support (or at least I'm not aware of any).

To get the clicked point coordinates, as any QWidget instance you can simply reimplement the 'mousePressEvent' method (see http://doc.qt.io/qt-4.8/qwidget.html#mousePressEvent).

And to close the previous window, you have to keep the pointer on the previous dialog (hDlg - preferably as a QSharedPointer by the way) and then use this pointer to 'close' the dialog. Another option is to use the 'exec' function of the dialog after 'show' (this will show the dialog in 'modal' mode, preventing the user from accessing the rest of the application, and he/she will need to close the dialog before doing anything else - this way you are sure the previous dialog is closed ;). And a last option is to give a unique name to the dialog (with setObjectName) and then later ask to its parent (the main window for instance?) with QObject::findChild.

Re: Some questions about qcustomplot

Posted: Wed Apr 19, 2017 9:25 am
by snfge
Hi
When I set the object name it OK it like"hDlg->setObjectName("TEST");", but when I find the child is bad, why?
it like"
ccHistogramWindowDlg* hDlg;
hDlg=MainWindow::TheInstance()->findChild("TEST");

Error: there is no function template matching the parameters

Re: Some questions about qcustomplot

Posted: Wed Apr 19, 2017 7:31 pm
by daniel
The method returns a Qt class instance. Therefore you have to ask for a QDialog:

Code: Select all

QDialog* dlg = MainWindow::TheInstance()->findChild<QDialog*>("TEST");
And if you get an instance, you will be able to cast it to a ccHistogramWindowDlg instance (pointer). Probably better with a 'dynamic_cast'.

Code: Select all

ccHistogramWindowDlg* hDlg = dynamic_cast<ccHistogramWindowDlg*>(dlg);

Re: Some questions about qcustomplot

Posted: Thu Apr 20, 2017 2:16 am
by snfge
Hi
I have solvled the problem, but I have another question, how can I get the XY for the dlg, I get it use rect, but the x=0, and y=0, I want show some info when I click on the dlg, and show the info at the position where I click, how can I do it?

Re: Some questions about qcustomplot

Posted: Fri Apr 21, 2017 8:29 am
by daniel
You'll need to take a closer look at Qt's documentation... the 'rect' method return the size of the dialog. To get its absolute position you need to call 'pos' (or 'geometry' if you want the position relative to the dialog's parent).

Refer to http://doc.qt.io/qt-4.8/application-win ... w-geometry