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. [SOLVED]How to delete an item from the treeview by droping an item to pushbutton or to an group box
Forum Updated to NodeBB v4.3 + New Features

[SOLVED]How to delete an item from the treeview by droping an item to pushbutton or to an group box

Scheduled Pinned Locked Moved General and Desktop
drag and droptreeview
54 Posts 4 Posters 22.3k Views 3 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.
  • RatzzR Ratzz

    @mrjj
    Since the groupbox is deletes item as you suggested it also deletes listview items when dragged.

    mrjjM Offline
    mrjjM Offline
    mrjj
    Lifetime Qt Champion
    wrote on last edited by
    #39

    @Ratzz
    And the DragGBox do have
    void dragEnterEvent(QDragEnterEvent* event) {
    event->acceptProposedAction();
    }

    So why cant you just check that sender if the accepted one and then acccept or if not then
    reject the drop?

    RatzzR 1 Reply Last reply
    0
    • mrjjM mrjj

      @Ratzz
      And the DragGBox do have
      void dragEnterEvent(QDragEnterEvent* event) {
      event->acceptProposedAction();
      }

      So why cant you just check that sender if the accepted one and then acccept or if not then
      reject the drop?

      RatzzR Offline
      RatzzR Offline
      Ratzz
      wrote on last edited by
      #40

      @mrjj
      dragEnterEvent shoud be used for main class?

      --Alles ist gut.

      mrjjM 1 Reply Last reply
      0
      • RatzzR Ratzz

        @mrjj
        dragEnterEvent shoud be used for main class?

        mrjjM Offline
        mrjjM Offline
        mrjj
        Lifetime Qt Champion
        wrote on last edited by
        #41

        @mrjj said:
        For the DropGroupBox class.
        I assume you use that one?

        RatzzR 1 Reply Last reply
        0
        • mrjjM mrjj

          @mrjj said:
          For the DropGroupBox class.
          I assume you use that one?

          RatzzR Offline
          RatzzR Offline
          Ratzz
          wrote on last edited by Ratzz
          #42

          @mrjj
          yes i have used this one.
          Since its different class how to pull the sender to it?
          can you just drop me some piece of code.

          --Alles ist gut.

          1 Reply Last reply
          0
          • ? Guest
            RatzzR Offline
            RatzzR Offline
            Ratzz
            wrote on last edited by
            #43

            @mrjj
            Not it does not allow even the treeview items to drop

            --Alles ist gut.

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

              STOP
              sender() not working for events it seems.
              So cannot work.
              So its a no go.

              RatzzR 1 Reply Last reply
              0
              • mrjjM mrjj

                STOP
                sender() not working for events it seems.
                So cannot work.
                So its a no go.

                RatzzR Offline
                RatzzR Offline
                Ratzz
                wrote on last edited by
                #45

                @mrjj
                ok fine.. what next?!

                --Alles ist gut.

                mrjjM 1 Reply Last reply
                0
                • RatzzR Ratzz

                  @mrjj
                  ok fine.. what next?!

                  mrjjM Offline
                  mrjjM Offline
                  mrjj
                  Lifetime Qt Champion
                  wrote on last edited by
                  #46

                  @Ratzz
                  you can use
                  QWidget * QDropEvent::source() const

                  read here
                  http://doc.qt.io/qt-5.5/qdropevent.html#source

                  RatzzR 1 Reply Last reply
                  0
                  • mrjjM mrjj

                    @Ratzz
                    you can use
                    QWidget * QDropEvent::source() const

                    read here
                    http://doc.qt.io/qt-5.5/qdropevent.html#source

                    RatzzR Offline
                    RatzzR Offline
                    Ratzz
                    wrote on last edited by
                    #47

                    @mrjj
                    this way?

                        void dragEnterEvent(QDragEnterEvent* event) {
                            QWidget * theone= dynamic_cast<QWidget*>(event->source());
                            if( theone == NULL )
                            {
                                event->acceptProposedAction();
                            }
                        }

                    --Alles ist gut.

                    mrjjM 1 Reply Last reply
                    0
                    • RatzzR Ratzz

                      @mrjj
                      this way?

                          void dragEnterEvent(QDragEnterEvent* event) {
                              QWidget * theone= dynamic_cast<QWidget*>(event->source());
                              if( theone == NULL )
                              {
                                  event->acceptProposedAction();
                              }
                          }
                      mrjjM Offline
                      mrjjM Offline
                      mrjj
                      Lifetime Qt Champion
                      wrote on last edited by mrjj
                      #48

                      @Ratzz
                      almost but must be the type you want to allow
                      QTreeView * theone= dynamic_cast<QTreeView*>(event->source());
                      if( theone != NULL )
                      {
                      event->acceptProposedAction();
                      }

                      so it says if it IS a Treeview then say ok
                      For other types, it should not allow then. (red sign)
                      I hope :)

                      1 Reply Last reply
                      0
                      • RatzzR Offline
                        RatzzR Offline
                        Ratzz
                        wrote on last edited by Ratzz
                        #49

                        @mrjj
                        yes its working fine :)
                        i should implement for Pushbutton also .

                        --Alles ist gut.

                        mrjjM 1 Reply Last reply
                        0
                        • RatzzR Ratzz

                          @mrjj
                          yes its working fine :)
                          i should implement for Pushbutton also .

                          mrjjM Offline
                          mrjjM Offline
                          mrjj
                          Lifetime Qt Champion
                          wrote on last edited by
                          #50

                          @Ratzz
                          Super :)

                          RatzzR 1 Reply Last reply
                          0
                          • mrjjM mrjj

                            @Ratzz
                            Super :)

                            RatzzR Offline
                            RatzzR Offline
                            Ratzz
                            wrote on last edited by
                            #51

                            @mrjj
                            when i click delete button i do ui->label->setText(QString::number(parent->rowCount())); which gives me count of the number of rows. But if i drag the row will be deleted but count is not getting updated. how to update it ?
                            Should it be done on GroupDropBox??

                            --Alles ist gut.

                            mrjjM 1 Reply Last reply
                            0
                            • RatzzR Ratzz

                              @mrjj
                              when i click delete button i do ui->label->setText(QString::number(parent->rowCount())); which gives me count of the number of rows. But if i drag the row will be deleted but count is not getting updated. how to update it ?
                              Should it be done on GroupDropBox??

                              mrjjM Offline
                              mrjjM Offline
                              mrjj
                              Lifetime Qt Champion
                              wrote on last edited by
                              #52

                              @Ratzz
                              GroupBox would not know about parent.
                              The Tree should update when the It is removed.

                              But then you drag, do you call the buttons on_click so the
                              ui->label->setText(QString::number(parent->rowCount()))
                              is executed ?
                              The groupBox example does not call anything as the Tree removes the item it self so
                              I assume that is why you dont see Count Changes.

                              mrjjM 1 Reply Last reply
                              0
                              • mrjjM mrjj

                                @Ratzz
                                GroupBox would not know about parent.
                                The Tree should update when the It is removed.

                                But then you drag, do you call the buttons on_click so the
                                ui->label->setText(QString::number(parent->rowCount()))
                                is executed ?
                                The groupBox example does not call anything as the Tree removes the item it self so
                                I assume that is why you dont see Count Changes.

                                mrjjM Offline
                                mrjjM Offline
                                mrjj
                                Lifetime Qt Champion
                                wrote on last edited by
                                #53

                                Hi
                                you could also cheat a bit and use a timer.

                                QTimer *timer = new QTimer(this);
                                connect(timer, SIGNAL(timeout()), this, SLOT(updateMinorFrameCount()));
                                timer->start(1000);

                                RatzzR 1 Reply Last reply
                                1
                                • mrjjM mrjj

                                  Hi
                                  you could also cheat a bit and use a timer.

                                  QTimer *timer = new QTimer(this);
                                  connect(timer, SIGNAL(timeout()), this, SLOT(updateMinorFrameCount()));
                                  timer->start(1000);

                                  RatzzR Offline
                                  RatzzR Offline
                                  Ratzz
                                  wrote on last edited by
                                  #54

                                  @mrjj
                                  cheating works fine :)

                                  --Alles ist gut.

                                  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