Results 1 to 5 of 5

Thread: Problem with MouseEvents

  1. #1
    Join Date
    Dec 2014
    Posts
    3
    Thanks
    2
    Qt products
    Qt5
    Platforms
    Windows

    Default Problem with MouseEvents

    I have this in my Dialog header:
    Qt Code:
    1. void mousePressEvent(QMouseEvent *);
    2. void mouseMoveEvent(QMouseEvent*);
    3. void mouseReleaseEvent(QMouseEvent *);
    To copy to clipboard, switch view to plain text mode 
    And this in my cpp:

    Qt Code:
    1. scene=new QGraphicsScene(0,0,800,600);
    2. ui->graphicsView->setScene(scene);
    3. QPixmap p2("C:/Users/Pedro/Desktop/imagens/6.jpg");
    4. scene->addItem(item);
    To copy to clipboard, switch view to plain text mode 

    Is possible to open a new window or to do any action when the item is clicked? Sorry people, I'm begginer. Can you help me, please?
    Qt Code:
    1. void Dialog::mousePressEvent(QMouseEvent * e) {
    2.  
    3. }
    To copy to clipboard, switch view to plain text mode 

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

    Default Re: Problem with MouseEvents

    Subclass the item class and reimplement its mousePressEvent handler. Or subclass the scene or the view and reimplement mousePressEvent there. However in the latter two cases you will first have to detect if you are pointing on an item.
    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. The following user says thank you to wysota for this useful post:

    pedrohs (5th December 2014)

  4. #3
    Join Date
    Dec 2014
    Posts
    3
    Thanks
    2
    Qt products
    Qt5
    Platforms
    Windows

    Default Re: Problem with MouseEvents

    I did what you said. But now I need to set a QPixmap for my subclass.
    What can I do in the constructor to replace this part of my code?

    Qt Code:
    1. QPixmap p2("C:/Users/Pedro/Desktop/imagens/6.jpg");
    2. scene->addItem(item);
    To copy to clipboard, switch view to plain text mode 

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

    Default Re: Problem with MouseEvents

    Replace QGraphicsPixmapItem with the class you created.
    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.


  6. The following user says thank you to wysota for this useful post:

    pedrohs (5th December 2014)

  7. #5
    Join Date
    Dec 2014
    Posts
    3
    Thanks
    2
    Qt products
    Qt5
    Platforms
    Windows

    Default Re: Problem with MouseEvents

    You saved my life. Thank you.

Similar Threads

  1. QGraphicsProxyWidget and mouseEvents
    By qlands in forum Qt Programming
    Replies: 2
    Last Post: 11th November 2010, 17:15
  2. QTableWidget mouseEvents
    By QAir in forum Qt Programming
    Replies: 6
    Last Post: 28th July 2009, 16:11
  3. qwt mouseEvents
    By halberdier83 in forum Qwt
    Replies: 7
    Last Post: 22nd April 2009, 12:37
  4. how to show fillRect() using mouseEvents??
    By thomasjoy in forum Qt Programming
    Replies: 9
    Last Post: 31st August 2007, 14:30
  5. QGraphicsView mouseEvents...?
    By thill2708 in forum Qt Programming
    Replies: 1
    Last Post: 29th November 2006, 20:20

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.