add rightbutton only can dray

This commit is contained in:
chenshijie
2020-11-02 19:07:49 +08:00
parent 85a577fe90
commit 7b9079d279
3 changed files with 32 additions and 8 deletions

View File

@@ -6,7 +6,8 @@ MoveWidget::MoveWidget(QObject *parent) : QObject(parent)
{
lastPoint = QPoint(0, 0);
pressed = false;
leftButton = true;
leftButton = false;
rightButton = false;
inControl = true;
widget = 0;
}
@@ -16,8 +17,12 @@ bool MoveWidget::eventFilter(QObject *watched, QEvent *event)
if (widget != 0 && watched == widget) {
QMouseEvent *mouseEvent = (QMouseEvent *)event;
if (mouseEvent->type() == QEvent::MouseButtonPress) {
//如果限定了只能鼠标左键拖动则判断当前是否是鼠标左键
if (leftButton && mouseEvent->button() != Qt::LeftButton) {
//如果鼠标左键和鼠标右键都可以拖动
if (leftButton && rightButton) {
}
//如果限定了只能鼠标左键拖动则判断当前是否是鼠标左键,如果限定了只能鼠标右键拖动则判断当前是否是鼠标右键
else if ((leftButton && mouseEvent->button() != Qt::LeftButton) || (rightButton && mouseEvent->button() != Qt::RightButton)) {
return false;
}
@@ -68,6 +73,11 @@ void MoveWidget::setLeftButton(bool leftButton)
this->leftButton = leftButton;
}
void MoveWidget::setRightButton(bool rightButton)
{
this->rightButton = rightButton;
}
void MoveWidget::setInControl(bool inControl)
{
this->inControl = inControl;