Results 1 to 8 of 8

Thread: Reimplementing mouseMoveEvent function in QGraphicsProxyWidget does not work.

  1. #1
    Join Date
    Aug 2013
    Posts
    5
    Qt products
    Qt4 Qt5
    Platforms
    Unix/X11 Windows Android

    Default 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:

    Qt Code:
    1. rectItem->setFlags(QGraphicsItem::ItemIsMovable | QGraphicsItem::ItemIsSelectable);
    2. scene->addItem(rectItem);
    3.  
    4. QDial *label = new QDial();
    5. label->setMouseTracking(true);
    6. ProxyWidget *proxyWidget = new ProxyWidget(rectItem);
    7. proxyWidget->setWidget(label);
    To copy to clipboard, switch view to plain text mode 

    Qt Code:
    1. void ProxyWidget::mousePressEvent(QGraphicsSceneMouseEvent *e)
    2. {
    3. if (this->isMovable)
    4. e->ignore(); //[1]
    5. else
    6. e->accept();
    7. }
    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.
    Last edited by Binpix; 30th August 2013 at 02:26.

  2. #2
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,363
    Thanks
    3
    Thanked 5,012 Times in 4,791 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: Reimplementing mouseMoveEvent function in QGraphicsProxyWidget does not work.

    Quote Originally Posted by Binpix View Post
    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.
    Your biological and technological distinctiveness will be added to our own. Resistance is futile.

    Please ask Qt related questions on the forum and not using private messages or visitor messages.


  3. #3
    Join Date
    Sep 2008
    Location
    Bangalore
    Posts
    658
    Thanks
    116
    Thanked 42 Times in 41 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: Reimplementing mouseMoveEvent function in QGraphicsProxyWidget does not work.

    im facing something similar ..
    Qt Code:
    1. ProxyWidget::ProxyWidget(const QRectF &bounds, QGraphicsItem *parent)
    2. : QGraphicsObject(parent), m_bounds(bounds)
    3. {
    4. QGraphicsProxyWidget *proxy = new QGraphicsProxyWidget(this);
    5. QDial *dial = new QDial();
    6. dial->setFixedSize(m_bounds.width(), m_bounds.height());
    7. dial->setFocusPolicy(Qt::StrongFocus);
    8. dial->setMouseTracking(true);
    9. dial->installEventFilter(this);
    10. proxy->setWidget(dial);
    11. proxy->setPos(0, 0);
    12.  
    13. }
    To copy to clipboard, switch view to plain text mode 
    Qt Code:
    1. bool
    2. ProxyWidget::eventFilter(QObject *obj, QEvent *watched)
    3. {
    4. if (watched->type() == QEvent::MouseButtonPress )
    5. {
    6.  
    7. qDebug()<<"Mouse Move Debug";
    8. return true;
    9.  
    10. }
    11. return true;
    12. }
    To copy to clipboard, switch view to plain text mode 

    this not showing any dial view but if i remove installEventFilter then rest is fine ..
    "Behind every great fortune lies a crime" - Balzac

  4. #4
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,363
    Thanks
    3
    Thanked 5,012 Times in 4,791 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default 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.
    Your biological and technological distinctiveness will be added to our own. Resistance is futile.

    Please ask Qt related questions on the forum and not using private messages or visitor messages.


  5. #5
    Join Date
    Sep 2008
    Location
    Bangalore
    Posts
    658
    Thanks
    116
    Thanked 42 Times in 41 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: Reimplementing mouseMoveEvent function in QGraphicsProxyWidget does not work.

    Quote Originally Posted by wysota View Post
    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 ..
    "Behind every great fortune lies a crime" - Balzac

  6. #6
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,363
    Thanks
    3
    Thanked 5,012 Times in 4,791 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: Reimplementing mouseMoveEvent function in QGraphicsProxyWidget does not work.

    Please start your own thread instead of hijacking this one.
    Your biological and technological distinctiveness will be added to our own. Resistance is futile.

    Please ask Qt related questions on the forum and not using private messages or visitor messages.


  7. #7
    Join Date
    Aug 2013
    Posts
    5
    Qt products
    Qt4 Qt5
    Platforms
    Unix/X11 Windows Android

    Default Re: Reimplementing mouseMoveEvent function in QGraphicsProxyWidget does not work.

    Quote Originally Posted by wysota View Post
    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:

    Qt Code:
    1. void ProxyWidget::mouseMoveEvent(QGraphicsSceneMouseEvent *e)
    2. {
    3. qDebug() << "mouseMoveEvent";
    4.  
    5. if (!this->isMovable) // If it is not in edtition mode
    6. QGraphicsProxyWidget::mouseMoveEvent(e);
    7. }
    To copy to clipboard, switch view to plain text mode 

    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?

  8. #8
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,363
    Thanks
    3
    Thanked 5,012 Times in 4,791 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: Reimplementing mouseMoveEvent function in QGraphicsProxyWidget does not work.

    You can always ignore the event in the widget.
    Your biological and technological distinctiveness will be added to our own. Resistance is futile.

    Please ask Qt related questions on the forum and not using private messages or visitor messages.


Similar Threads

  1. Replies: 3
    Last Post: 1st May 2013, 20:44
  2. reimplementing mouseMoveEvent of QGraphicsItem
    By MTW in forum Qt Programming
    Replies: 1
    Last Post: 18th December 2010, 17:45
  3. Replies: 1
    Last Post: 11th May 2010, 14:29
  4. problem reimplementing mouseMoveEvent
    By jhowland in forum Qt Programming
    Replies: 2
    Last Post: 6th April 2010, 20:18
  5. qSort doesn't work with member function
    By ber_44 in forum Qt Programming
    Replies: 10
    Last Post: 2nd June 2007, 12:00

Tags for this Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Digia, Qt and their respective logos are trademarks of Digia Plc in Finland and/or other countries worldwide.