sách gpt4 ăn đã đi

c++ - 通过鼠标右键而不是左键使 QGraphicsItem 可移动

In lại Tác giả: Walker 123 更新时间:2023-11-30 05:24:36 32 4
mua khóa gpt4 giày nike

是否可以创建一个可移动的 QGraphicsItem,它可以用鼠标右键而不是左键移动?

我唯一能通过搜索找到的是一个线程 which suggests using QGraphicsItem::setAcceptedMouseButtons() ,我尝试将其设置为仅接受右键单击,但随后项目根本无法移动。

这是我试过的代码:

QGraphicsScene *scene = new QGraphicsScene(this);
ui->graphicsView->setScene(scene);
QGraphicsRectItem *item = scene->addRect(0, 0, 100, 100);
item->setFlag(QGraphicsItem::ItemIsMovable);
item->setAcceptedMouseButtons(Qt::RightButton);

câu trả lời hay nhất

我最终查看了源代码,@G.M.指出,QGraphicsItem::mouseMoveEvent() 的代码明确检查鼠标左键:

void QGraphicsItem::mouseMoveEvent(QGraphicsSceneMouseEvent *event)
{
if ((event->buttons() & Qt::LeftButton) && (flags() & ItemIsMovable)) {

所以除了在派生类中重新实现移动之外什么也做不了。

关于c++ - 通过鼠标右键而不是左键使 QGraphicsItem 可移动,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/38605930/

32 4 0
Walker 123
Hồ sơ

Tôi là một lập trình viên xuất sắc, rất giỏi!

Nhận phiếu giảm giá taxi Didi miễn phí
Phiếu giảm giá taxi Didi
Chứng chỉ ICP Bắc Kinh số 000000
Hợp tác quảng cáo: 1813099741@qq.com 6ren.com
Xem sitemap của VNExpress