I have a 2D Chart with static data(not real time). What I want is to have a slider like the real time view port example for the 2D chart. Slider should have zooming functionality. (When user moves the slider, it suppose to zoom to that part of the chart) I've tried to mimic the real time view port example with no luck.
QFrame *lowerFrame = new QFrame(this->m_p_chart_viewer);
lowerFrame->setGeometry(0, 355, 640, 64);
The code above is the inside of the constructor of chart class. Result of it was a blank frame on the chart. if I remove the lowerFrame parameter from QViewPortControl's constructor it draws the exact same chart in a new window without slider. Am I missing something? What would you suggest?
As I do not know what is "this->m_p_chart_viewer", I am unable to comment on the Qt layout of your code, such as why you need to set the parent of the QViewPortControl to be the lowerFrame, which in turns use this->m_p_chart_viewer as the parent.
It seems the QViewPortControl cannot be visible. The lowerFrame is only 64 pixels high, but you put the QViewPortControl at 355 pixels below the top edge of the frame, so it is way outside the lowerFrame. If you need an example, please use our sample code as an example.
When you use a viewport control, your code need to draw two charts:
(a) A chart that acts as a background image of the viewport control. This is usually a chart that shows the full data range.
(b) A chart that only includes the selected data range to be displayed in the QChartViewer. This chart is drawn whenever the viewport is changed.
In your code, you use the same chart for the QChartViewer and QViewPortControl, so the two charts are the same as expected. Please use the sample code as an example.