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. Add Data with a QPushButton to QTreeView
Forum Updated to NodeBB v4.3 + New Features

Add Data with a QPushButton to QTreeView

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

    Hi,

    I have two QTreeViews. The first one is filled with Data. Now I want to select data from this view and add it by clicking on a QPushButton to a second QTreeView.

    I know that I have to connect the QPushButton to a method that is adding the data. My problem is that I don't know how the method should look like.

    Thanks for help.

    1 Reply Last reply
    0
    • A Offline
      A Offline
      AcerExtensa
      wrote on last edited by
      #2

      Simply connect your pusshButton to the slot:
      @
      ....
      connect(this->btn_copy, SIGNAL(clicked()), this, SLOT(copy_clicked()));
      ...
      @

      in this slot just copy item from one treeview to another:
      @
      void YourClass::copy_clicked()
      {
      this->tree_view_right->addItem(this->tree_view_left->itemAt(this->tree_vew_left->currentIndex()));
      }
      @

      God is Real unless explicitly declared as Integer.

      1 Reply Last reply
      0
      • T Offline
        T Offline
        Tortura
        wrote on last edited by
        #3

        Thanks for your reply.

        I connected my button and wrote the copy_clicked() method but when I start my program I get this error:

        Object::connect: No such slot MyClass::copy_clicked()
        Object::connect: (sender name: 'btn_copy')
        Object::connect: (receiver name: 'Dialog')

        What did I do wrong?

        1 Reply Last reply
        0
        • T Offline
          T Offline
          Tortura
          wrote on last edited by
          #4

          Weird, I placed the method in front of the connect command and the errors don't appear anymore. BUT nothing else is happening.

          1 Reply Last reply
          0
          • A Offline
            A Offline
            AcerExtensa
            wrote on last edited by
            #5

            have you declared your slot in class declaration? Like:
            @
            private slots:
            void copy_clicked();
            @

            God is Real unless explicitly declared as Integer.

            1 Reply Last reply
            0
            • A Offline
              A Offline
              AcerExtensa
              wrote on last edited by
              #6

              Have you read about signals and slots already? "Signals and slots":http://doc.qt.digia.com/qt/signalsandslots.html

              God is Real unless explicitly declared as Integer.

              1 Reply Last reply
              0
              • T Offline
                T Offline
                Tortura
                wrote on last edited by
                #7

                I'm a beginner with Qt and programming with Python and PyQt. Therefore it's a bit complicated to rethink the c++ code in python and how to do everything right.

                Because I became desperate with this problem I posted it here and thought that I can solve this problem. I'll read the "Signals and slots" article. Thanks.

                1 Reply Last reply
                0
                • T Offline
                  T Offline
                  Tortura
                  wrote on last edited by
                  #8

                  I tried something else. And now by starting the program it says

                  'QTreeView' object has no attribute addItem

                  Do I have to implement the addItem() method by myself?

                  1 Reply Last reply
                  0
                  • A Offline
                    A Offline
                    AcerExtensa
                    wrote on last edited by
                    #9

                    Yes, addItem was just from my head... use right method to insert element to the treeview...

                    God is Real unless explicitly declared as Integer.

                    1 Reply Last reply
                    0
                    • A Offline
                      A Offline
                      AcerExtensa
                      wrote on last edited by
                      #10

                      If you use QTreeWidget instead of QTreeView this method will already exist... (addItem, insertItem, etc...)

                      God is Real unless explicitly declared as Integer.

                      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