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. QPushButton in a QTableView
Forum Updated to NodeBB v4.3 + New Features

QPushButton in a QTableView

Scheduled Pinned Locked Moved General and Desktop
11 Posts 6 Posters 15.8k 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.
  • G Offline
    G Offline
    giesbert
    wrote on last edited by
    #2

    Hi,

    there are different options.

    use the edit triggers to open the editor also on other events then double click

    overwrite the delegates paint event

    use "setIndexWidget":http://qt-project.org/doc/qt-4.8/qabstractitemview.html#setIndexWidget

    Nokia Certified Qt Specialist.
    Programming Is Like Sex: One mistake and you have to support it for the rest of your life. (Michael Sinz)

    1 Reply Last reply
    0
    • O Offline
      O Offline
      Octani
      wrote on last edited by
      #3

      Ok thanks you.
      So I try to use the setIndexWidget() which works perfectly, the problem is I don't understand how to retrieve the line where the button is clicked. Because from the QPushButton it's not possible.

      So I use the void QAbstractItemView::clicked ( const QModelIndex & index ) [signal] method but it doesn't work. The slot is not called.

      1 Reply Last reply
      0
      • G Offline
        G Offline
        giesbert
        wrote on last edited by
        #4

        You should use a QSignalMapper object for that.

        Nokia Certified Qt Specialist.
        Programming Is Like Sex: One mistake and you have to support it for the rest of your life. (Michael Sinz)

        1 Reply Last reply
        0
        • S Offline
          S Offline
          Sam
          wrote on last edited by
          #5

          Hi,

          You need to create a slot and then connect that slot to the tableView . eg

          @connect(tableView,SLOT(clicked(QModelIndex)),this,SLOT(on_tableView_clicked(QModelIndex));@

          If you are using Qt designer then just right click on your tableView ---Go to Slot--clicked(QModelIndex)

          then in the function you can filter the row and column from the index

          @void MainWindow::on_tableView_clicked(const QModelIndex &index)
          {
          qDebug() << index.row() << " " << index.column();
          }@

          but while running the application if you Left Click on the pushbutton this slot is not called but if you press Right Click then this slot is called and it prints the row and column this is what i am getting.

          1 Reply Last reply
          0
          • O Offline
            O Offline
            Octani
            wrote on last edited by
            #6

            Exactly, I didn't see that.
            And there's no way to emit this signal after a Left Click on the pushbutton? Because users will never find they must right click.

            edit : I never used QSignalMapper, how does this tool can help me?

            1 Reply Last reply
            0
            • G Offline
              G Offline
              giesbert
              wrote on last edited by
              #7

              You can connect a signal of an object with the signal mapper and send a signal from the mapper together with an ID. It's done exactly for those purposes.

              Have a look "at the docs":http://qt-project.org/doc/qt-4.8/qsignalmapper.html#details . you could use the setMapping(QObject*, int) part.

              Nokia Certified Qt Specialist.
              Programming Is Like Sex: One mistake and you have to support it for the rest of your life. (Michael Sinz)

              1 Reply Last reply
              0
              • R Offline
                R Offline
                rschaub
                wrote on last edited by
                #8

                you could also use a custom delegate to create a button in the desired cell (like you suggested in the initial post). Then, in order to show them permanently, call "openPersistentEditor":http://qt-project.org/doc/qt-4.8/qabstractitemview.html#openPersistentEditor

                to find out which row or column the button is in, simply store them in the properties of the button when creating it.

                1 Reply Last reply
                0
                • L Offline
                  L Offline
                  lukeQt
                  wrote on last edited by
                  #9

                  Do you have an example of overloading the delegates paint event?

                  1 Reply Last reply
                  0
                  • SGaistS Offline
                    SGaistS Offline
                    SGaist
                    Lifetime Qt Champion
                    wrote on last edited by
                    #10

                    Hi,

                    "Here":http://qt-project.org/doc/qt-5/qtwidgets-itemviews-stardelegate-example.html it is

                    Interested in AI ? www.idiap.ch
                    Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

                    1 Reply Last reply
                    0
                    • L Offline
                      L Offline
                      lukeQt
                      wrote on last edited by
                      #11

                      Hi SGaist,

                      Thank you. I also added the tag for solved.

                      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