作者热门文章
- Java 双重比较
- java - 比较器与 Apache BeanComparator
- Objective-C 完成 block 导致额外的方法调用?
- database - RESTful URI 是否应该公开数据库主键?
我想问一个关于qcustomplot的问题。如何根据 Slider 更改 itemLine 位置? (比如 x = a)
#include "itemline.h"
#include "ui_itemline.h"
#include "qcustomplot.h"
itemLine::itemLine(QWidget *parent) :
QMainWindow(parent),
ui(new Ui::itemLine)
{
ui->setupUi(this);
QCPItemLine *item = new QCPItemLine(ui->customPlot);
ui->customPlot->addItem(item);
item->setPen(QPen(Qt::red));
item->start->setCoords(1,0);
item->end->setCoords(1,5);
connect(ui->horizontalSlider, SIGNAL(valueChanged(int)), this, SLOT(horzSliderChanged(int)));
}
itemLine::~itemLine()
{
delete ui;
}
void itemLine::horzSliderChanged(int value)
{
// how can i change item position acording to horizontalSlider, like "x = a" line ?
}
最佳答案
首先,您应该将指向 QCPItemLine
的指针保留为类成员。之后 horzSliderChanged
槽可能是这样的:
void itemLine::horzSliderChanged(int value)
{
item->start->setCoords(value,0);
item->end->setCoords(value,5);
ui->customPlot->replot();
}
关于c++ - QCustomPlot QCPItemLine,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/27357095/
将 QCPItemLine 与图层一起使用的正确方法是什么?我有一个像素放大器,我用 QCustomPlot 在网格上绘制,我想在像素图上方画一条线,到目前为止它显示在像素图下方。 假设我已经设置了一
我正在尝试在我的图形用户界面中使用 QCustomPlot 主窗口.h public: void initArrow(); private: QCustomPlot* grid; QCPItemLin
我想问一个关于qcustomplot的问题。如何根据 Slider 更改 itemLine 位置? (比如 x = a) #include "itemline.h" #include "ui_item
我是一名优秀的程序员,十分优秀!