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. Is it possible to sync. selection of 2 GraphicScenes while keeping mutliselection ?
Forum Updated to NodeBB v4.3 + New Features

Is it possible to sync. selection of 2 GraphicScenes while keeping mutliselection ?

Scheduled Pinned Locked Moved Solved General and Desktop
5 Posts 2 Posters 320 Views
  • 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.
  • GilboonetG Offline
    GilboonetG Offline
    Gilboonet
    wrote on last edited by
    #1

    Hello, My application uses 2 graphic scenes/views, one for 3d view and the other for 2d view. The goal of my app is to select faces of the current 3d model to work on them. When the user select faces on the 3d model, the 3d equivalent faces must also be selected, and reciprocally. I tried to implement that by adding an handler for SelectionChanged events :

                connect(dep->scene3d, &QGraphicsScene::selectionChanged, this, &MainWindow::SelectionDansScene3D);
                connect(dep->scene2d, &QGraphicsScene::selectionChanged, this, &MainWindow::SelectionDansScene2D);
    
    

    the handlers are :

    void MainWindow::SelectionDansScene3D()
    {
        if (!selEnCours) {
            dep->scene2d->clearSelection();
            selEnCours = true;
            for(auto&& i : dep->scene3d->selectedItems()) {
                int ni = i->data(0).toInt();
                for(auto && j : dep->t2d) {
                    if (ni == j->id) {
                        j->setSelected(true);
                        break;
                    }
                }
            }
            selEnCours = false;
        }
    }
    
    void MainWindow::SelectionDansScene2D()
    {
        if (!selEnCours) {
            dep->scene3d->clearSelection();
            selEnCours = true;
            for(auto&& i : dep->scene2d->selectedItems()) {
                int ni = i->data(0).toInt();
                for(auto && j : dep->scene3d->items()) {
                    int nj = j->data(0).toInt();
                    if (ni == nj) {
                        auto v = dep->meshModel->faces[ni].voisins;
                        qDebug() << "sel2D : " << ni << " - " << nj << " (" << v[0].nF << ", " << v[1].nF << ", " << v[2].nF << ")";
                        j->setSelected(true);
                    }
                }
            }
            selEnCours = false;
        }
    }
    

    But with those event handlers, it is no more possible to multi select using the mouse (it works using the rubberband), and when I move the 3d scene I lose the selection (I added a list where I save the current selection and retrieve it after I redraw the 3d scene but it doesn't work with SelectionChanged events handlers) . After I disabled those handlers I can both multi select with the mouse and the current selection remains when I rotate the 3d view. Is there something I can do to have those lost functionnalities ?

    1 Reply Last reply
    0
    • GilboonetG Offline
      GilboonetG Offline
      Gilboonet
      wrote on last edited by
      #2

      I finally added a function to disconnect/connect the SelectionChanged events handlers so that they don't fire everytime I change a selection by code. I am now able to keep a multi selection while rotating the 3d model.

      JonBJ 1 Reply Last reply
      0
      • GilboonetG Gilboonet has marked this topic as solved on
      • GilboonetG Gilboonet

        I finally added a function to disconnect/connect the SelectionChanged events handlers so that they don't fire everytime I change a selection by code. I am now able to keep a multi selection while rotating the 3d model.

        JonBJ Offline
        JonBJ Offline
        JonB
        wrote on last edited by
        #3

        @Gilboonet
        ...Or maintain a (shared) boolean flag for which state you are in and test this to decide to do code or nothing in SelectionDansScene... slots rather than disconnecting and reconnecting signals....

        GilboonetG 1 Reply Last reply
        0
        • JonBJ JonB

          @Gilboonet
          ...Or maintain a (shared) boolean flag for which state you are in and test this to decide to do code or nothing in SelectionDansScene... slots rather than disconnecting and reconnecting signals....

          GilboonetG Offline
          GilboonetG Offline
          Gilboonet
          wrote on last edited by
          #4

          @JonB I started by doing exactly like you suggest as the code shows but apparently firing the events stop the multi selection from propagating or something alike.

          JonBJ 1 Reply Last reply
          0
          • GilboonetG Gilboonet

            @JonB I started by doing exactly like you suggest as the code shows but apparently firing the events stop the multi selection from propagating or something alike.

            JonBJ Offline
            JonBJ Offline
            JonB
            wrote on last edited by
            #5

            @Gilboonet Oh, OK.

            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