Results 1 to 2 of 2

Thread: Change the cursor of a widget inside a QGraphicsProxyWidget

  1. #1
    Join Date
    Feb 2012
    Posts
    2
    Qt products
    Qt4
    Platforms
    Windows

    Default Change the cursor of a widget inside a QGraphicsProxyWidget

    Hi everyone,

    I have got a problem to change the cursor shape of my widget on a left click in it.

    Context (Qt 4.8, win 7):
    I have a QGraphicsScene containing a QGraphicsProxyWidget. This proxy hold my widget.
    Qt Code:
    1. QGraphicsProxyWidget proxy;
    2. MyWidget widget;
    3. proxy.setWidget(aWidget);
    4. scene.addItem(proxy);
    To copy to clipboard, switch view to plain text mode 

    In MyWidget class, I have override the function mousepress & mouserelease as :

    Qt Code:
    1. void MyWidget::mousePressEvent(QMouseEvent *ev){
    2. if(ev->button() == Qt::LeftButton){
    3. setCursor(QCursor(Qt::OpenHandCursor));
    4. }
    5. }
    6.  
    7. void MyWidget::mouseReleaseEvent(QMouseEvent *ev){
    8.  
    9. }
    To copy to clipboard, switch view to plain text mode 

    For information, MyWidget override also the repaintEvent
    Qt Code:
    1. void MyWidget::paintEvent(QPaintEvent* p){
    2. QPainter painter(this);
    3. painter.drawPixmap(0,0,pp);
    4. }
    To copy to clipboard, switch view to plain text mode 

    The problem is the mouse cursor only change when I press the left button of the mouse in the widget and I move my mouse out of the widget and go back again in it focus.

    I have tested my code by showing MyWidget as a classic window (MyWidget::show()) and the cursor immediately change when I press the left mouse button.


    I certainly miss something to add when the widget is in a proxy.

    Thanks for your help,

    Paolo

  2. #2
    Join Date
    Feb 2012
    Posts
    2
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: Change the cursor of a widget inside a QGraphicsProxyWidget

    Not the best way for sur, but a solution is to have a mapping beetween the widget and the proxy, we will call the proxy "parent"

    the code will be something like :

    Qt Code:
    1. void MyWidget::mousePressEvent(QMouseEvent *ev){
    2. if(ev->button() == Qt::LeftButton){
    3. //parent is the proxy containing MyWidget
    4. parent->setCursor(QCursor(Qt::OpenHandCursor));
    5. }
    6. }
    7.  
    8. void MyWidget::mouseReleaseEvent(QMouseEvent *ev){
    9. parent->setCursor(QCursor(Qt::ArrowCursor));
    10. }
    To copy to clipboard, switch view to plain text mode 

    I hope that will help someone.

    Paolo

Similar Threads

  1. CSS cursor property not working inside QWebView
    By ynonp in forum Qt Programming
    Replies: 1
    Last Post: 30th August 2011, 23:39
  2. Change cursor inside QTableview
    By big4mil in forum Qt Programming
    Replies: 4
    Last Post: 15th November 2010, 11:04
  3. Replies: 0
    Last Post: 27th July 2010, 12:48
  4. Replies: 8
    Last Post: 9th July 2010, 00:37
  5. change cursor
    By nicky in forum Qt Programming
    Replies: 2
    Last Post: 31st January 2007, 11:07

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
  •  
Qt is a trademark of The Qt Company.