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. Is it possible to modify header/footer of ListView.???
Qt 6.11 is out! See what's new in the release blog

Is it possible to modify header/footer of ListView.???

Scheduled Pinned Locked Moved QML and Qt Quick
10 Posts 6 Posters 8.7k Views 1 Watching
  • 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.
  • A Offline
    A Offline
    aekam
    wrote on last edited by
    #1

    Hello,

    Is it possible to modify the header/footer of the ListView.??
    say I have a header and footer components, each having a Text in it...
    Now upon and mouse click I want to change the text of header and footer.

    If you take care of inches, you won't have to worry about miles... :)

    1 Reply Last reply
    0
    • M Offline
      M Offline
      mkuettler
      wrote on last edited by
      #2

      Hello.

      I do not quite understand your question. A QListView does not display a header.
      But it sounds like you might want to do something like connecting the signal
      @
      signal:
      void clicked(const QModelIndex & index))
      @

      of your ListView to some function, that updates the element if it is a header or footer.

      1 Reply Last reply
      0
      • M Offline
        M Offline
        MuldeR
        wrote on last edited by
        #3

        I think this is a bit tricky. The QListView or QTableView is just a "view" control. All it's data, inclduing the text for the header, is taken from the QAbstractItemModel that the view is connected to. The model doesn't know anything about the view(s). You may connect a slot to the clicked() signal of the view and, inside that slot, react on the click-event by modifying the model accordingly. Your model would need some suitable "setter" method for this purpose. But keep in mind that an arbitrary number of views may be connected to the same model!

        My OpenSource software at: http://muldersoft.com/

        Qt v4.8.6 MSVC 2013, static/shared: http://goo.gl/BXqhrS

        Go visit the coop: http://youtu.be/Jay...

        1 Reply Last reply
        0
        • A Offline
          A Offline
          aekam
          wrote on last edited by
          #4

          I am working in QML...
          where I have ListView like,

          @
          ListView {
          header : headerComponent
          footer : footerComponent
          model : inputModel
          delegate : outputModel
          }

          Component {
          id : headerComponent
          Text {
          }
          }
          @

          If you take care of inches, you won't have to worry about miles... :)

          1 Reply Last reply
          0
          • M Offline
            M Offline
            mkuettler
            wrote on last edited by
            #5

            Connecting to signals also works in QML, but I am not sure how you would have to write that. You might get better answers if you asked your question in the Qt Quick forum; http://qt-project.org/forums/viewforum/12/ .

            1 Reply Last reply
            0
            • EddyE Offline
              EddyE Offline
              Eddy
              wrote on last edited by
              #6

              I moved this one as suggested.

              But i still don't understand what you want exactly. Can you elaborate?

              Eg clicking on an item, you can get an ID and use that to get data from the model and set it as text in the header component. Is that what you want?

              For QML the same advise from MuldeR about model/view is important.

              Qt Certified Specialist
              www.edalsolutions.be

              1 Reply Last reply
              0
              • EddyE Offline
                EddyE Offline
                Eddy
                wrote on last edited by
                #7

                [quote author="mkuettler" date="1337976569"]Connecting to signals also works in QML, but I am not sure how you would have to write that. You might get better answers if you asked your question in the Qt Quick forum; http://qt-project.org/forums/viewforum/12/ .[/quote]

                "You can use Connections element":http://qt-project.org/doc/qt-4.8/qml-connections.html
                It is also possible to use C++ combined with QML. "Here is a good start":http://qt-project.org/wiki/Introduction_to_Qt_Quick_for_Cpp_developers

                Qt Certified Specialist
                www.edalsolutions.be

                1 Reply Last reply
                0
                • D Offline
                  D Offline
                  dicksonleong
                  wrote on last edited by
                  #8

                  Maybe u can try:

                  @
                  ListView{
                  id: listView
                  property Item headerItem
                  header: Text{
                  id: headerComponent
                  text: "Header"
                  Component.onCompleted: listView.headerItem = headerComponent
                  }
                  }

                  MouseArea{
                  onClicked: listView.headerItem.text = "ABC"
                  }
                  @

                  1 Reply Last reply
                  0
                  • A Offline
                    A Offline
                    aekam
                    wrote on last edited by
                    #9

                    I doubt about this to work... May be it is not possible to alter the header footer components.

                    If you take care of inches, you won't have to worry about miles... :)

                    1 Reply Last reply
                    0
                    • B Offline
                      B Offline
                      bibek
                      wrote on last edited by
                      #10

                      First I thought it is possible but it seems that header or footer element id is not recognized properly. Here's the modified code that worked for me.
                      Main point is using a universal scoped variable

                      @import QtQuick 1.1
                      import com.nokia.symbian 1.1

                      Page {

                      property string buttonText : "OK"
                      
                      ListView {
                          id: list_view1
                          anchors.fill: parent
                          
                          delegate: Item {
                              x: 5
                              height: 40
                              
                              
                              
                              Row {
                                  id: row1
                                  spacing: 10
                                  Rectangle {
                                      width: 40
                                      height: 40
                                      color: colorCode
                                  }
                                  
                                  Text {
                                      text: name
                                      anchors.verticalCenter: parent.verticalCenter
                                      font.bold: true
                                      color: "white"
                                  }
                                  Button {
                                      id: button1
                                      x: 272
                                      y: 0
                                      text: "Button"
                                      onClicked : buttonText = model.name
                                  }
                              }
                          }
                          model: ListModel {
                              ListElement {
                                  name: "Grey"
                                  colorCode: "grey"
                              }
                              
                              ListElement {
                                  name: "Red"
                                  colorCode: "red"
                              }
                          }
                          
                          header: ToolButton {
                              id : button
                              text: buttonText
                          }
                          
                          Button {
                              id: button1x
                              x: 272
                              y: 0
                              text: "Button"
                              onClicked: buttonText = "It works"
                          }
                      }
                      

                      }
                      @

                      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