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. QtableView how to find the proper signal

QtableView how to find the proper signal

Scheduled Pinned Locked Moved General and Desktop
signalqtableviewqsqlquerymodelselection
12 Posts 3 Posters 7.2k 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.
  • S Offline
    S Offline
    SGaist
    Lifetime Qt Champion
    wrote on 1 Jul 2015, 23:41 last edited by
    #2

    Hi,

    What about using the hasSelection method ?

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

    C 1 Reply Last reply 2 Jul 2015, 06:28
    0
    • S SGaist
      1 Jul 2015, 23:41

      Hi,

      What about using the hasSelection method ?

      C Offline
      C Offline
      cpuin
      wrote on 2 Jul 2015, 06:28 last edited by
      #3

      @SGaist
      The problem is that hasSelection() is a method, i need a signal.Now i can use only currentRowChanged(), but it doesn't emit when nothing is selected.I need every time when the table has selected row to be possible to delete and when there is no selection to be not possible.

      1 Reply Last reply
      0
      • C Offline
        C Offline
        Chris Kawa
        Lifetime Qt Champion
        wrote on 2 Jul 2015, 18:08 last edited by
        #4

        You can connect to selectionChanged() signal and use selectedRows()inside the connected slot to check if any row is selected.

        C 1 Reply Last reply 2 Jul 2015, 19:01
        0
        • C Chris Kawa
          2 Jul 2015, 18:08

          You can connect to selectionChanged() signal and use selectedRows()inside the connected slot to check if any row is selected.

          C Offline
          C Offline
          cpuin
          wrote on 2 Jul 2015, 19:01 last edited by
          #5

          @Chris-Kawa

          i did this

          connect(ui->tableView_partners->selectionModel(), SIGNAL(selectionChanged(QItemSelection,QItemSelection)),
                      this, SLOT(enableDeleteButton()));
          

          void Partners::enableDeleteButton()
          {

          if (ui->tableView_partners->selectionModel()->selectedRows().isEmpty())
          {
              ui->pushButton_delete->setEnabled(false);
           }
          
          else {
          
              ui->pushButton_delete->setEnabled(true);
          }
          

          }

          Unfortunately it works until new row is added.When a row is added there is no selected index in the tableView, but the button is enabled.Probably after adding row tableView selection is empty, but the model by default has last row selected or something like this.
          Is it possible aways to have selected rows?Any ideas?

          1 Reply Last reply
          0
          • S Offline
            S Offline
            SGaist
            Lifetime Qt Champion
            wrote on 3 Jul 2015, 21:01 last edited by
            #6

            Do you mean enableDeleteButton is not called if you add a new row to the table ?

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

            C 1 Reply Last reply 3 Jul 2015, 21:31
            0
            • S SGaist
              3 Jul 2015, 21:01

              Do you mean enableDeleteButton is not called if you add a new row to the table ?

              C Offline
              C Offline
              cpuin
              wrote on 3 Jul 2015, 21:31 last edited by
              #7

              @SGaist
              YES

              1 Reply Last reply
              0
              • S Offline
                S Offline
                SGaist
                Lifetime Qt Champion
                wrote on 3 Jul 2015, 21:43 last edited by
                #8

                So adding a new row clears the current selection and this doesn't result in your slot being called ? Sounds like it could be a little bug.

                Can you reproduce this with a minimal compilable example ?

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

                C 1 Reply Last reply 6 Jul 2015, 09:22
                0
                • S SGaist
                  3 Jul 2015, 21:43

                  So adding a new row clears the current selection and this doesn't result in your slot being called ? Sounds like it could be a little bug.

                  Can you reproduce this with a minimal compilable example ?

                  C Offline
                  C Offline
                  cpuin
                  wrote on 6 Jul 2015, 09:22 last edited by
                  #9

                  @SGaist

                  Here is the link to the example: Example
                  What i want to achieve is when there is no selected row the button to be disabled.It works, but when select row and click add (adding new record) the button remain enabled, but no row is selected.Another option that i don't prefer is the view to have always selected row.

                  1 Reply Last reply
                  0
                  • S Offline
                    S Offline
                    SGaist
                    Lifetime Qt Champion
                    wrote on 16 Jul 2015, 13:25 last edited by
                    #10

                    I'm not fluent in Russian at all, I only saw the publicities. Where's the download ?

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

                    C 1 Reply Last reply 16 Jul 2015, 16:19
                    0
                    • S SGaist
                      16 Jul 2015, 13:25

                      I'm not fluent in Russian at all, I only saw the publicities. Where's the download ?

                      C Offline
                      C Offline
                      cpuin
                      wrote on 16 Jul 2015, 16:19 last edited by
                      #11

                      @SGaist
                      Not only Russians use Cyrillic :) i'm bulgarian.I reuploaded the example here

                      1 Reply Last reply
                      0
                      • S Offline
                        S Offline
                        SGaist
                        Lifetime Qt Champion
                        wrote on 28 Jul 2015, 22:50 last edited by
                        #12

                        Sorry for the late reply, the page says that there's nothing to be found

                        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

                        • Login

                        • Login or register to search.
                        • First post
                          Last post
                        0
                        • Categories
                        • Recent
                        • Tags
                        • Popular
                        • Users
                        • Groups
                        • Search
                        • Get Qt Extensions
                        • Unsolved