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 default selection

QTableView default selection

Scheduled Pinned Locked Moved Unsolved General and Desktop
11 Posts 5 Posters 2.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.
  • N Offline
    N Offline
    nammidd
    wrote on last edited by
    #1

    By default, how to select the first row in QTableView with QFileSystemModel? When i use table->selectRow(0) it selects nothing, when i use QObject::connect(model, &QFileSystemModel::directoryLoaded, [&]{table->selectRow(0);}); it selects fourth row.
    But if i use table->selectRow(0) in events (void keyPressEvent(QKeyEvent *event) for example), it works ok, what is the problem?

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

      Hi,

      Did you check the path returned by directoryLoaded ? Is it the one you expect ?

      In any case, I'd use the model's index method to get the row corresponding to the loaded path.

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

      N 1 Reply Last reply
      1
      • VRoninV Offline
        VRoninV Offline
        VRonin
        wrote on last edited by
        #3

        table->selectionModel()->select(table->model()->index(0,0),QItemSelectionModel::ClearAndSelect);

        "La mort n'est rien, mais vivre vaincu et sans gloire, c'est mourir tous les jours"
        ~Napoleon Bonaparte

        On a crusade to banish setIndexWidget() from the holy land of Qt

        1 Reply Last reply
        1
        • SGaistS SGaist

          Hi,

          Did you check the path returned by directoryLoaded ? Is it the one you expect ?

          In any case, I'd use the model's index method to get the row corresponding to the loaded path.

          N Offline
          N Offline
          nammidd
          wrote on last edited by
          #4

          @SGaist Hot to check the path returned by directoryLoaded? Where does it returns the path?
          @VRonin It does not work. Selects nothing.

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

            It's given in parameter of the 'directoryLoaded' signal.

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

            N 1 Reply Last reply
            1
            • SGaistS SGaist

              It's given in parameter of the 'directoryLoaded' signal.

              N Offline
              N Offline
              nammidd
              wrote on last edited by nammidd
              #6
              This post is deleted!
              1 Reply Last reply
              0
              • N Offline
                N Offline
                nammidd
                wrote on last edited by nammidd
                #7

                The problem is solved, it seems that QTableView performs sorting after directory loaded.
                Is there a way to prevent sorting?

                JonBJ Prince_0912P 2 Replies Last reply
                0
                • N nammidd

                  The problem is solved, it seems that QTableView performs sorting after directory loaded.
                  Is there a way to prevent sorting?

                  JonBJ Offline
                  JonBJ Offline
                  JonB
                  wrote on last edited by
                  #8

                  @nammidd
                  What about http://doc.qt.io/qt-5/qtableview.html#sortingEnabled-prop ?

                  N 1 Reply Last reply
                  2
                  • JonBJ JonB

                    @nammidd
                    What about http://doc.qt.io/qt-5/qtableview.html#sortingEnabled-prop ?

                    N Offline
                    N Offline
                    nammidd
                    wrote on last edited by
                    #9

                    @JonB This option only allows to change sorting order (from ascending to descending or vice versa), by clicking on the column header. But the sorting is done anyway, regardless of whether the option is turned on or off.

                    1 Reply Last reply
                    0
                    • N nammidd

                      The problem is solved, it seems that QTableView performs sorting after directory loaded.
                      Is there a way to prevent sorting?

                      Prince_0912P Offline
                      Prince_0912P Offline
                      Prince_0912
                      wrote on last edited by
                      #10

                      @nammidd ,
                      I think you can use setting false to setSortingEnabled.
                      For this you can use this link .

                      N 1 Reply Last reply
                      0
                      • Prince_0912P Prince_0912

                        @nammidd ,
                        I think you can use setting false to setSortingEnabled.
                        For this you can use this link .

                        N Offline
                        N Offline
                        nammidd
                        wrote on last edited by
                        #11

                        @Prince_0912
                        @nammidd said in QTableView default selection:

                        @JonB This option only allows to change sorting order (from ascending to descending or vice versa), by clicking on the column header. But the sorting is done anyway, regardless of whether the option is turned on or off.

                        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