Qt Forum

    • Login
    • Search
    • Categories
    • Recent
    • Tags
    • Popular
    • Users
    • Groups
    • Search
    • Unsolved

    Update: Forum Guidelines & Code of Conduct

    How to add item to listview

    QML and Qt Quick
    3
    9
    2785
    Loading More Posts
    • 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
      Roey1234560 last edited by

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

      1 Reply Last reply Reply Quote 0
      • dheerendra
        dheerendra Qt Champions 2022 last edited by

        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 Reply Quote 0
        • R
          Roey1234560 last edited by

          it's qt , the listview widget(QListView)

          1 Reply Last reply Reply Quote 0
          • V
            Vincent007 last edited by

            "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 Reply Quote 0
            • R
              Roey1234560 last edited by

              and how i get the selected index?

              1 Reply Last reply Reply Quote 0
              • V
                Vincent007 last edited by

                Did you read document?

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

                1 Reply Last reply Reply Quote 0
                • R
                  Roey1234560 last edited by

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

                  1 Reply Last reply Reply Quote 0
                  • dheerendra
                    dheerendra Qt Champions 2022 last edited by

                    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 Reply Quote 0
                    • V
                      Vincent007 last edited by

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

                      1 Reply Last reply Reply Quote 0
                      • First post
                        Last post