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. [SOLVED]How to click the first row in Qlistview by default ?
Forum Update on Monday, May 27th 2025

[SOLVED]How to click the first row in Qlistview by default ?

Scheduled Pinned Locked Moved General and Desktop
qlistview
9 Posts 3 Posters 10.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.
  • R Offline
    R Offline
    Ratzz
    wrote on 3 Aug 2015, 11:20 last edited by Ratzz 8 May 2015, 04:37
    #1

    I have some items in the qlistview . I want the first row to be clicked by default (no column in listview)
    i have used signal clicked if the user click the items . But i want item0 to be clicked by default.

    connect(ui->listView_Messages,SIGNAL(clicked(QModelIndex)),this,SLOT(listViewClicked(QModelIndex)));
    

    --Alles ist gut.

    1 Reply Last reply
    0
    • S Offline
      S Offline
      SGaist
      Lifetime Qt Champion
      wrote on 3 Aug 2015, 11:31 last edited by
      #2

      Hi,

      Do you mean selected ? If so use QItemSelectionModel::select
      You can retrieve the selection model directly from your QListView.

      Hope it helps

      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
      • R Offline
        R Offline
        Ratzz
        wrote on 3 Aug 2015, 11:43 last edited by
        #3

        @SGaist
        Thanks for the reply
        It will just select the item0.
        My signal clicked will not trigger by default.

        --Alles ist gut.

        1 Reply Last reply
        0
        • D Offline
          D Offline
          Devopia
          wrote on 3 Aug 2015, 13:46 last edited by
          #4

          Hi

          You can invoke the signal as a event.

          QMetaObject::invokeMethod(ui->listView_Messages, "clicked", Qt::QueuedConnection, Q_ARG(QModelIndex, QModelIndex()));

          1 Reply Last reply
          1
          • S Offline
            S Offline
            SGaist
            Lifetime Qt Champion
            wrote on 3 Aug 2015, 13:47 last edited by
            #5

            The correct way to select an item is using the selection model. The clicked signal is emitted on mouse interaction.

            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
            • R Offline
              R Offline
              Ratzz
              wrote on 4 Aug 2015, 04:40 last edited by
              #6

              @Devopia
              Thanks for the reply.
              I tried invoke the signal as a event as you mentioned but did not work for me.
              Should i add index of the model which is set to list-view ? If so how to include?

              --Alles ist gut.

              1 Reply Last reply
              0
              • R Offline
                R Offline
                Ratzz
                wrote on 4 Aug 2015, 04:46 last edited by
                #7

                @SGaist
                This did not work for me .

                QModelIndex Index= ui->listView_Messages->model()->index(0,0);
                ui->listView_Messages->selectionModel()->select( Index, QItemSelectionModel::Select );
                

                Did i miss anything?

                --Alles ist gut.

                1 Reply Last reply
                0
                • S Offline
                  S Offline
                  SGaist
                  Lifetime Qt Champion
                  wrote on 4 Aug 2015, 20:02 last edited by
                  #8

                  Silly question but is Index valid ?

                  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
                  • R Offline
                    R Offline
                    Ratzz
                    wrote on 5 Aug 2015, 04:36 last edited by Ratzz 8 May 2015, 04:36
                    #9

                    @SGaist
                    Have set the listview to model and fetched the index from model.

                    --Alles ist gut.

                    1 Reply Last reply
                    0

                    8/9

                    4 Aug 2015, 20:02

                    • Login

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