【发布时间】:2018-08-24 04:21:05
【问题描述】:
我想在 QGraphicsView 中移动 QPushButton 或某种 QWidget,例如 QListWidet、QTableWidget 等。
所以,我使用了 QGraphicsProxyWidget。
然后我单击小部件并拖动。但它不动。
如何移动 QWidget?
这是我的代码。
ui->graphicsView->setGeometry(0,0,geometry().width(),geometry().height());
scene = new QGraphicsScene(0, 0, geometry().width(), geometry().height(), this);
ui->graphicsView->setScene(scene);
btn =new QPushButton(NULL);
QGraphicsProxyWidget *proxy = scene->addWidget(btn);
proxy->setFlags(QGraphicsItem::ItemIsMovable|QGraphicsItem::ItemIsSelectable);
scene->addItem(proxy);
你能告诉我有什么问题吗?
谢谢。
【问题讨论】:
-
一种常见的方法是处理主框架(按钮所在的位置)的鼠标按下、鼠标释放和鼠标移动事件,然后重新绘制按钮并刷新主框架。
-
嗯.. 我不明白你的评论。那么,你能给我看一个小例子吗?谢谢宏地@macroland
标签: c++ qt qgraphicsview