Skip to content

Commit

Permalink
"Implement" QMouseEvent::setLocalPos in Qt < 5.8
Browse files Browse the repository at this point in the history
  • Loading branch information
pzhlkj6612 committed Jan 21, 2020
1 parent 44a727e commit 9c51e31
Showing 1 changed file with 12 additions and 2 deletions.
14 changes: 12 additions & 2 deletions BesWidgets/BesSlider.h
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,12 @@ class BesSlider :public QSlider
qDebug()<<"BesSlider::mouseMoveEvent: "<<ev->pos();

// 通过偏移计算 handle 的正确位置
//ev->setLocalPos(ev->pos() += click_pos_offset);//?没有该函数?
#if QT_VERSION >= 0x050800
ev->setLocalPos(ev->pos() += click_pos_offset);
#else
QMouseEvent new_ev(ev->type(), ev->pos() += click_pos_offset, ev->button(), ev->buttons(), ev->modifiers());
ev = &new_ev;
#endif

// 如果需要在 enableMouseEvt == false 时,鼠标移动到 handle 上也改变鼠标样式,就去掉关于 enableMouseEvt 的判断。
if (enableMouseEvt && getHandleRect().contains(ev->pos())) {
Expand Down Expand Up @@ -92,7 +97,12 @@ class BesSlider :public QSlider
qDebug()<<"click_pos_offset:"<<click_pos_offset;

//用 handle 中心点代替实际点击位置,避免在点击到 handle 非中心位置时移动 handle,使 handle 看起来是能在任何位置被拖动的
//ev->setLocalPos(center_of_handle);//?没有该函数?
#if QT_VERSION >= 0x050800
ev->setLocalPos(center_of_handle);
#else
QMouseEvent new_ev(ev->type(), center_of_handle, ev->button(), ev->buttons(), ev->modifiers());
ev = &new_ev;
#endif
}else{
qDebug() << "handle not clicked";

Expand Down

0 comments on commit 9c51e31

Please sign in to comment.