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 ?
QtWS25 Last Chance

[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.
  • RatzzR Offline
    RatzzR Offline
    Ratzz
    wrote on last edited by Ratzz
    #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
    • SGaistS Offline
      SGaistS Offline
      SGaist
      Lifetime Qt Champion
      wrote on 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
      • RatzzR Offline
        RatzzR Offline
        Ratzz
        wrote on 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 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
          • SGaistS Offline
            SGaistS Offline
            SGaist
            Lifetime Qt Champion
            wrote on 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
            • RatzzR Offline
              RatzzR Offline
              Ratzz
              wrote on 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
              • RatzzR Offline
                RatzzR Offline
                Ratzz
                wrote on 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
                • SGaistS Offline
                  SGaistS Offline
                  SGaist
                  Lifetime Qt Champion
                  wrote on 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
                  • RatzzR Offline
                    RatzzR Offline
                    Ratzz
                    wrote on last edited by Ratzz
                    #9

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

                    --Alles ist gut.

                    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