Hello,
I am doing a program which allow to put, move and resize QWidget (QSlider, QPushButton, QDial...) inside a workspace. This workspace is a QGraphicView. I use a QGraphicsProxyWidget with a QGraphicsRectItem as parent to be able to move it easily and I give my widget to ProxyWidget which is inherited from QGraphicsProxyWidget.
Then, to resize my widget, I try to reimplement the functions mousePressEvent() (which works well) and mouseMoveEvent() but it does not work.
I tried to do setMouseTracking(true) on my widget, but nothing.
Here my code:
scene->addItem(rectItem);
label->setMouseTracking(true);
ProxyWidget *proxyWidget = new ProxyWidget(rectItem);
proxyWidget->setWidget(label);
QGraphicsRectItem* rectItem = new QGraphicsRectItem();
rectItem->setFlags(QGraphicsItem::ItemIsMovable | QGraphicsItem::ItemIsSelectable);
scene->addItem(rectItem);
QDial *label = new QDial();
label->setMouseTracking(true);
ProxyWidget *proxyWidget = new ProxyWidget(rectItem);
proxyWidget->setWidget(label);
To copy to clipboard, switch view to plain text mode
{
if (this->isMovable)
e->ignore(); //[1]
else
e->accept();
}
void ProxyWidget::mousePressEvent(QGraphicsSceneMouseEvent *e)
{
if (this->isMovable)
e->ignore(); //[1]
else
e->accept();
}
To copy to clipboard, switch view to plain text mode
In ProxyWidget I have just reimplemented mousePressEvent() and mouseMoveEvent().
Any idea?
EDIT: If I change e->ignore() by e->accept() mouseMoveEvent() works. But I cannot move my widget anymore because my widget get the focus, for exemple for a QPushButton, the button is pushed.
Bookmarks