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. QGraphicsProxyWidget > Qlabel get mouseMove/Release events?
Forum Updated to NodeBB v4.3 + New Features

QGraphicsProxyWidget > Qlabel get mouseMove/Release events?

Scheduled Pinned Locked Moved Unsolved General and Desktop
6 Posts 2 Posters 1.5k 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.
  • D Offline
    D Offline
    Dariusz
    wrote on last edited by
    #1

    Hey

    I'm trying to get an event response from my QLabel that is set to be QGraphicsProxyWidget.

    In my QGraphicsView I set

    void test::mouseMoveEvent(QMouseEvent *event){
        if(itemAt(event->pos()){
        return;}
       QGraphicsView::mouseMoveEvent(event);
    }
    

    But no matter what I do, I cant get the events to show up in proxyWidget or QLabel itself. How can I forward them to the correct widget? The GraphicsView event dont match with QGraphicsSceneMouseEvent so I'm bit lost ?

    Regards
    Dariusz

    1 Reply Last reply
    0
    • mrjjM Offline
      mrjjM Offline
      mrjj
      Lifetime Qt Champion
      wrote on last edited by mrjj
      #2

      Hi
      Normally the widget that are inserted into the proxy just works.

      See this small sample

      #include <QGraphicsProxyWidget>
      #include <QGraphicsScene>
      #include <QGraphicsView>
      #include <QMessageBox>
      #include <QPushButton>
      #include <QDebug>
      
      int main(int argc, char** argv) {
        QApplication app(argc, argv);
      
        QPushButton* button = new QPushButton("CLICK ME");
      
        QObject::connect(button, &QPushButton::clicked, [ = ]() {
          QMessageBox::warning(0, "Hello from widget", "Im alive");
        } );
      
        QGraphicsScene scene;
        QGraphicsProxyWidget* proxy = scene.addWidget(button);
        QGraphicsView view(&scene);
        view.show();
      
        return app.exec();
      }
      
      

      alt text

      Do you put them in an qgraphicsitemgroup ?

      Also , normally a QLabel do not have any mousePressEvent override so i assume you use something like https://wiki.qt.io/Clickable_QLabel
      to make it clickable. ?

      1 Reply Last reply
      1
      • D Offline
        D Offline
        Dariusz
        wrote on last edited by
        #3

        Hey
        Mmmm tricky. I realized I did not need to use proxyWiwdget but QGraphicsPixmapItem was sufficient. So I stayed at View level and handled it all from there for now, but I'm still puzzled.

        Say you have

        QGraphicsPixmapItem and you click on it and do mouse move. Would I like to forward the event from QGraphicsView to QGraphicsPixmapItem as that does not happen as standard? How can I do that? I think that View by default would attempt to move the item in the scene. But I don't want to do this. I just want to pass press/move/release events to the underlying item.

        1 Reply Last reply
        0
        • mrjjM Offline
          mrjjM Offline
          mrjj
          Lifetime Qt Champion
          wrote on last edited by mrjj
          #4

          Hi
          Can we talk about what goal is ?
          If you think QGraphicsPixmapItem is what you need i guess that you first
          tried to show pixmap in a QLabel.
          Since the pixmap have no methods for handling any input in not really sure
          why you try to forward events to it.

          Are you trying to make a clickable image or what is the overall goal ?
          If yes, please see this
          https://forum.qt.io/topic/60820/how-to-get-mouse-press-event-on-a-qpixmap/2

          1 Reply Last reply
          0
          • D Offline
            D Offline
            Dariusz
            wrote on last edited by
            #5

            The more I think of it the less I want to forward events to it actually... well maybe not. I want to have different items and then change their event behavior based on their types. So I thought I could forward it to them. Lets say I have a list view, I would like to forward mouseWheelEvent scroll to it when mouse is over the widget. Same goes for QImage/Pixmap I wanted to try some paint effect where I could paint on image in QGraphicsView so I can move it around anywhere/etc/etc.

            1 Reply Last reply
            0
            • mrjjM Offline
              mrjjM Offline
              mrjj
              Lifetime Qt Champion
              wrote on last edited by
              #6

              Hi
              If you want special items, i suggest you just create your own classes by subclassing
              QGraphicsItem. That way you can make them do whatever you like.

              Your example with ListView should work already as far as i know it can scroll with mouse3 but that needs a QGraphicsProxyWidget to function.

              As far as i know, one should use Proxy if you insert Widgets in the scene for them to fully function.

              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