Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. Mouse click events for QPixmapItem objects
Forum Updated to NodeBB v4.3 + New Features

Mouse click events for QPixmapItem objects

Scheduled Pinned Locked Moved General and Desktop
2 Posts 2 Posters 1.7k Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • M Offline
    M Offline
    Marcius
    wrote on last edited by
    #1

    Hi everyone,

    I'm playing around with Qt to get a grip of its basics, and can't seem to do it very well.

    Here's a few lines of my code:

    @int main(int argc, char *argv[])
    {
    QApplication app(argc, argv);

        QGraphicsScene scene;
        QGraphicsView view(&scene);
        QGraphicsPixmapItem item(QPixmap("C:\\card set\\s8.gif")),
                item2(QPixmap("C:\\card set\\s9.gif"));
        scene.addItem(&item), scene.addItem(&item2);
       view.show();
      return app.exec();
    

    }@

    How do I go about adding click events for these objects?
    Is there a more efficient way to declare and add items?

    I checked the documentation, but it still seems a bit confusing.

    I'd like to get quite a thorough explanation. Sorry if it seems noobish, but..I am very new to this.

    Thank you!

    1 Reply Last reply
    0
    • Chris KawaC Offline
      Chris KawaC Offline
      Chris Kawa
      Lifetime Qt Champion
      wrote on last edited by
      #2

      You can subclass QGraphicsView, implement mousePressEvent and use itemAt() like shown in "this example":http://qt-project.org/doc/qt-5/qgraphicsview.html#itemAt

      As for more info on how to use graphics view you can look at "these examples":http://qt-project.org/doc/qt-5/examples-graphicsview.html

      1 Reply Last reply
      0

      • Login

      • Login or register to search.
      • First post
        Last post
      0
      • Categories
      • Recent
      • Tags
      • Popular
      • Users
      • Groups
      • Search
      • Get Qt Extensions
      • Unsolved