QT和QPainter划清了界限。这条线可以用鼠标拖动吗?这个功能能实现吗?如果有,如何实现?

可以用mouseMoveEvent或者timer刷新鼠标坐标,然后重画。下面是计时器方法:

Draw::Draw(q widget * parent):q widget(parent)

{

m _ timer = new q timer(this);

connect(m_timer,SIGNAL(timeout()),this,SLOT(update SLOT()));

m _ timer-& gt;开始(10);

}

void Draw::updateSlot()

{

q point pos = mapFromGlobal(q cursor::pos());

m _ startX = pos . x();

m _ startY = pos . y();

update();

}

void Draw::paint event(QPaintEvent * event)

{

QPainter画师(这个);

painter.drawLine(m_startX,m_startY,m_startX+20,m _ startY+10);

}