Reimplementing mouseMoveEvent function in QGraphicsProxyWidget does not work.
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:
Code:
scene->addItem(rectItem);
label->setMouseTracking(true);
ProxyWidget *proxyWidget = new ProxyWidget(rectItem);
proxyWidget->setWidget(label);
Code:
{
if (this->isMovable)
e->ignore(); //[1]
else
e->accept();
}
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.
Re: Reimplementing mouseMoveEvent function in QGraphicsProxyWidget does not work.
Quote:
Originally Posted by
Binpix
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.
How would you define "works" and "does not work" in this case? To me it seems both your approaches "work", they just doesn't do what you want.
Re: Reimplementing mouseMoveEvent function in QGraphicsProxyWidget does not work.
im facing something similar ..
Code:
: QGraphicsObject(parent), m_bounds(bounds)
{
QGraphicsProxyWidget *proxy = new QGraphicsProxyWidget(this);
dial->setFixedSize(m_bounds.width(), m_bounds.height());
dial->setFocusPolicy(Qt::StrongFocus);
dial->setMouseTracking(true);
dial->installEventFilter(this);
proxy->setWidget(dial);
proxy->setPos(0, 0);
}
Code:
bool
{
if (watched
->type
() == QEvent::MouseButtonPress ) {
qDebug()<<"Mouse Move Debug";
return true;
}
return true;
}
this not showing any dial view but if i remove installEventFilter then rest is fine ..
Re: Reimplementing mouseMoveEvent function in QGraphicsProxyWidget does not work.
And how is that related to the OP's question? Which part exactly is "similar"? I cannot see any similarities.
Re: Reimplementing mouseMoveEvent function in QGraphicsProxyWidget does not work.
Quote:
Originally Posted by
wysota
And how is that related to the OP's question? Which part exactly is "similar"? I cannot see any similarities.
i accepthat .. but why dial is not showing.. can u please tell me .. the same happens when i use QPushButton in place of QDial .. it will be always pressed ..
Re: Reimplementing mouseMoveEvent function in QGraphicsProxyWidget does not work.
Please start your own thread instead of hijacking this one.
Re: Reimplementing mouseMoveEvent function in QGraphicsProxyWidget does not work.
Quote:
Originally Posted by
wysota
How would you define "works" and "does not work" in this case? To me it seems both your approaches "work", they just doesn't do what you want.
You are right, both work but do not do what I want. If I do e->accept() in mousePressEvent(), mouseMoveEvent() is called in ProxyWidget but then the event is given to the widget owned by ProxyWidget. I would like to stop that because if the widget get the event I cannot move it.
I have found something:
Code:
{
qDebug() << "mouseMoveEvent";
if (!this->isMovable) // If it is not in edtition mode
QGraphicsProxyWidget::mouseMoveEvent(e);
}
When I do that, the widget does not get the event when I am in edition mode, but the parent which is a QGraphicsRectItem is not movable anymore.
How can I do to give the event to QGraphicsProxyWidget::mouseMoveEvent(e) but telling it to do not give the event to the widget?
Do I have to reimplement the move behaviour?
Re: Reimplementing mouseMoveEvent function in QGraphicsProxyWidget does not work.
You can always ignore the event in the widget.