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

QtableView how to find the proper signal

Scheduled Pinned Locked Moved General and Desktop
signalqtableviewqsqlquerymodelselection
12 Posts 3 Posters 7.2k 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.
  • SGaistS Offline
    SGaistS Offline
    SGaist
    Lifetime Qt Champion
    wrote on 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
    0
    • SGaistS SGaist

      Hi,

      What about using the hasSelection method ?

      C Offline
      C Offline
      cpuin
      wrote on 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
      • Chris KawaC Offline
        Chris KawaC Offline
        Chris Kawa
        Lifetime Qt Champion
        wrote on 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
        0
        • Chris KawaC Chris Kawa

          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 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
          • SGaistS Offline
            SGaistS Offline
            SGaist
            Lifetime Qt Champion
            wrote on 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
            0
            • SGaistS SGaist

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

              C Offline
              C Offline
              cpuin
              wrote on last edited by
              #7

              @SGaist
              YES

              1 Reply Last reply
              0
              • SGaistS Offline
                SGaistS Offline
                SGaist
                Lifetime Qt Champion
                wrote on 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
                0
                • SGaistS SGaist

                  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 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
                  • SGaistS Offline
                    SGaistS Offline
                    SGaist
                    Lifetime Qt Champion
                    wrote on 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
                    0
                    • SGaistS SGaist

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

                      C Offline
                      C Offline
                      cpuin
                      wrote on last edited by
                      #11

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

                      1 Reply Last reply
                      0
                      • SGaistS Offline
                        SGaistS Offline
                        SGaist
                        Lifetime Qt Champion
                        wrote on 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