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. Event handling : Accessing another widget's property [SOLVED]
Forum Updated to NodeBB v4.3 + New Features

Event handling : Accessing another widget's property [SOLVED]

Scheduled Pinned Locked Moved General and Desktop
7 Posts 2 Posters 1.6k 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.
  • C Offline
    C Offline
    ccbaci
    wrote on last edited by
    #1

    OK, this should be easy.

    I tried to handle drop event onto a QGraphicsView widget. Incoming data dragged from a QTreeView widget. For that, I re-implemented these methods:

    @void QGraphicsScene::dragEnterEvent(QGraphicsSceneDragDropEvent *event)
    {
    event.accept();
    }

    void QGraphicsScene::dragMoveEvent(QGraphicsSceneDragDropEvent *event)
    {
    event.accept();
    }

    void QGraphicsScene::dropEvent(QGraphicsSceneDragDropEvent *event)
    {
    event.accept();
    }

    void QGraphicsView::dropEvent(QDropEvent *event)
    {
    QPixmap pixmap(event->mimedata()->urls()[0].toString().remove(0,8));
    this.scene()->addPixmap(pixmap);
    }@

    This works fine; but how can I change another graphicsview scene within this widget's drop event? That is:

    @void QGraphicsView::dropEvent(QDropEvent *event)
    {
    QPixmap pixmap(event->mimedata()->urls()[0].toString().remove(0,8));
    // I cannot access ui; and cannot access other widgets...:
    ui->anotherview->scene()->addPixmap(pixmap);
    }@

    1 Reply Last reply
    0
    • sierdzioS Offline
      sierdzioS Offline
      sierdzio
      Moderators
      wrote on last edited by
      #2

      Well, does that not work? Are you getting any errors?

      (Z(:^

      1 Reply Last reply
      0
      • C Offline
        C Offline
        ccbaci
        wrote on last edited by
        #3

        Access to Mainwindow widgets from QGraphicsView class is forbidden.

        ui->anotherview doesn't work.

        Should I create a subclass of QGraphicsView (that inherits it), then promote my graphicsview widgets to that class and create signals there? Then I can connect to mainwindow slots. That was the only way I could think of.

        1 Reply Last reply
        0
        • sierdzioS Offline
          sierdzioS Offline
          sierdzio
          Moderators
          wrote on last edited by
          #4

          Wait so you have modified source code of Qt itself right now? I don't get your setup :)

          In general, since you are reimplementing events you should subclass. Then there are numerous ways to get to your main window and update the other scene.

          You can change mainWindow into a Singleton and then include it in your subclass (perfectly legal, although I find it ugly).

          You can use meta object system to get to your parent (which probably is your MainWindow), then find the other view using findChildren<>() and set the property using QObject::setProperty().

          Or you can send the signal from your subclass notifying your MainWindow (or anotherView directly) that a change needs to be made.

          (Z(:^

          1 Reply Last reply
          0
          • C Offline
            C Offline
            ccbaci
            wrote on last edited by
            #5

            I actually rewrote drag drop events of qgraphics and qscene :) I get "inconsistent dll" warning but it worked fine. I will subclass them right now. I will try the meta object method as the signalling method (which was the only thing i could think of) requires more effort.

            1 Reply Last reply
            0
            • C Offline
              C Offline
              ccbaci
              wrote on last edited by
              #6

              meta method worked fine man; thanks! btw, how do you accept an answer in this forum ? :)

              1 Reply Last reply
              0
              • sierdzioS Offline
                sierdzioS Offline
                sierdzio
                Moderators
                wrote on last edited by
                #7

                Hey, that's nice to hear! Happy coding!

                In general we just add "[Solved]" to the subject (edit your initial post, then add [Solved] to the title). I'll tag it for you.

                (Z(:^

                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