QCustomPlot和iRangeDrag在第二个右yAxis上
QCustomPlot and iRangeDrag on second right yAxis
我想让右轴可拖动
现在使用一个网站的例子,我可以使第一个yAxis
可拖动双击它。
void MainWindow::mousePress()
{
// if an axis is selected, only allow the direction of that axis to be dragged
// if no axis is selected, both directions may be dragged
if (ui->customPlot->xAxis->selectedParts().testFlag(QCPAxis::spAxis))
ui->customPlot->axisRect()->setRangeDrag(ui->customPlot->xAxis->orientation());
else if (ui->customPlot->yAxis->selectedParts().testFlag(QCPAxis::spAxis))
ui->customPlot->axisRect()->setRangeDrag(ui->customPlot->yAxis->orientation());
else if (ui->customPlot->yAxis2->selectedParts().testFlag(QCPAxis::spAxis))
ui->customPlot->axisRect()->setRangeDrag(ui->customPlot->yAxis2->orientation());
else
ui->customPlot->axisRect()->setRangeDrag(Qt::Horizontal|Qt::Vertical);
}
我的图有2条线,每条线都有不同的yAxis
。我想要实现的是在第二个(右边)yAxis
(称为yAxis2
)上实现相同的可拖动效果。下面的代码,即使我选择了yAxis2
,它是yAxis
被垂直拖动。
我猜问题是在axisRect(),这是只涉及到左边的yAxis,而不是他们两个。
我通过修改代码来解决这个问题,以便在右轴上也执行拖动调用。如果你看一下左轴上发生了什么,就会明白了。
我可以通过调用QCPAxisRect::setRangeDragAxes()
将yAxis
和yAxis2
拖动到一起。
注意:如果你仍然希望xAxis
用鼠标拖动,那么你需要把它也放在列表中,因为默认值将被覆盖。
QList<QCPAxis *> draggableAxes = {xAxis,yAxis,yAxis2};
myPlot->axisRect()->setRangeDragAxes(draggableAxes);
如果你想在缩放交互中也有类似的行为,也有一个setter !QCPAxisRect::setRangeZoomAxes()
相关文章:
- 我有两个类需要在同一 cpp 文件中相互引用,但第一个类无法识别第二个类类型的对象
- 等待整个 omp 块完成,然后再调用第二个函数
- 我想在C++中读取一些多个字符,但它永远不会读取第二个字符
- 如何在创建自定义迭代器时获得 std::p air 的第一个和第二个?
- WinAPI 在单击第一个对话框上的按钮控件并销毁第一个对话框后创建第二个对话框
- 将第二个 GATT 服务添加到 Movesense 容器
- 如何在 c++ 中根据第二个元素按降序对列表进行排序
- 对的排序向量 (std::vector<pair<int, int>>) 按对的第一个元素搜索并更新第二个元素值
- 比较 2 个向量并从第二个向量中删除在第一个 - c++ 中找不到的元素
- 为什么这个程序没有打印返回的迭代器的正确第二个元素?
- 使第二个类的构造函数成为第一个类中的友元函数
- 为什么第二个代码给出了预期的结果,而第一个代码却没有?
- 为什么第一个代码块产生垃圾值,而第二个代码块将类成员的值相加?
- 打印无序映射的第二个元素,即集合
- 我有一个类,它创建了另一个类的实例.如何将变量通过第一个类传递到第二个类的实例化中?
- 需要使用模板查找数组的第二个最小和最小值
- c++:交换向量中所有元组的第一个和第二个元素
- 如果条件,当我想第二个参数时
- 将内容从第一个文件("constituencies")移动到第二个文件("temp")并在之后重命名时,我的文件被删除
- QCustomPlot和iRangeDrag在第二个右yAxis上