Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. QML and Qt Quick
  4. How to add item to listview
QtWS25 Last Chance

How to add item to listview

Scheduled Pinned Locked Moved QML and Qt Quick
9 Posts 3 Posters 3.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
    Roey1234560
    wrote on last edited by
    #1

    I want to add item to my listview but i can't find how.
    I am new in Qt.

    1 Reply Last reply
    0
    • dheerendraD Offline
      dheerendraD Offline
      dheerendra
      Qt Champions 2022
      wrote on last edited by
      #2

      Is it in QML or Qt ? Please confirm. We can tell you. Anyway if you can refer QTableView in Qt or ListView in QML documentation give you good information. You need to use model to fill the data. Set the model to view. Then it will start displaying. You can use QListWidget as well. If you need sample, do let know. I can you send you the code.

      Dheerendra
      @Community Service
      Certified Qt Specialist
      http://www.pthinks.com

      1 Reply Last reply
      0
      • R Offline
        R Offline
        Roey1234560
        wrote on last edited by
        #3

        it's qt , the listview widget(QListView)

        1 Reply Last reply
        0
        • V Offline
          V Offline
          Vincent007
          wrote on last edited by
          #4

          "Using models and views":http://doc-snapshot.qt-project.org/qdoc/model-view-programming.html#using-models-and-views

          @
          QListView *list = new QListView(splitter);
          list->setModel(model);
          list->setRootIndex(model->index(QDir::currentPath()));
          @

          1 Reply Last reply
          0
          • R Offline
            R Offline
            Roey1234560
            wrote on last edited by
            #5

            and how i get the selected index?

            1 Reply Last reply
            0
            • V Offline
              V Offline
              Vincent007
              wrote on last edited by
              #6

              Did you read document?

              http://qt-project.org/doc/qt-5/qlistview.html#selectedIndexes

              1 Reply Last reply
              0
              • R Offline
                R Offline
                Roey1234560
                wrote on last edited by
                #7

                when i using this function i get compile error:
                'QListView::selectedIndexes' : cannot access protected member declared in class 'QListView'

                1 Reply Last reply
                0
                • dheerendraD Offline
                  dheerendraD Offline
                  dheerendra
                  Qt Champions 2022
                  wrote on last edited by
                  #8

                  Did you look at the signals from view ? activated, clicked etc signals are emitted with QModelIndex. This will give you the selected index.

                  Dheerendra
                  @Community Service
                  Certified Qt Specialist
                  http://www.pthinks.com

                  1 Reply Last reply
                  0
                  • V Offline
                    V Offline
                    Vincent007
                    wrote on last edited by
                    #9

                    I suggest you try QTPATH\examples\widgets\tutorials\modelview\7_selections

                    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