Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. Mobile and Embedded
  4. How to implement this UI effect (just like the Listview of android)for Android in qt ?I tried some classes like QListWidget、QListView,but they seems more suitable for PC
QtWS25 Last Chance

How to implement this UI effect (just like the Listview of android)for Android in qt ?I tried some classes like QListWidget、QListView,but they seems more suitable for PC

Scheduled Pinned Locked Moved Solved Mobile and Embedded
5 Posts 2 Posters 1.0k 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.
  • D Offline
    D Offline
    dmnc
    wrote on last edited by
    #1

    0_1543246170343_20181126231635.png

    Gojir4G 1 Reply Last reply
    0
    • D dmnc

      0_1543246170343_20181126231635.png

      Gojir4G Offline
      Gojir4G Offline
      Gojir4
      wrote on last edited by
      #2

      Hi @dmnc,

      You could achieve this with Qt Quick, using QML ListView and Material Style.

      It's more suitable for UI mobile development than Qt Widgets.

      D 1 Reply Last reply
      0
      • D Offline
        D Offline
        dmnc
        wrote on last edited by
        #3
        This post is deleted!
        1 Reply Last reply
        0
        • Gojir4G Gojir4

          Hi @dmnc,

          You could achieve this with Qt Quick, using QML ListView and Material Style.

          It's more suitable for UI mobile development than Qt Widgets.

          D Offline
          D Offline
          dmnc
          wrote on last edited by
          #4

          @Gojir4 thank you for your reply,I will try it.

          Gojir4G 1 Reply Last reply
          0
          • D dmnc

            @Gojir4 thank you for your reply,I will try it.

            Gojir4G Offline
            Gojir4G Offline
            Gojir4
            wrote on last edited by
            #5

            Hi @dmnc,

            Here is an basic example using QML:

            //file: main.qml
            import QtQuick 2.9
            import QtQuick.Controls 2.2
            import QtQuick.Controls.Material 2.2
            import QtQuick.Layouts 1.3
            
            ApplicationWindow {
                visible: true
                width: 480
                height: 640
                title: qsTr("Android ListView")
            
                //Taken from Toolbar documentation
                header: ToolBar {
                    RowLayout {
                        anchors.fill: parent
                        ToolButton {text: qsTr("☰")}
                        Label {
                            text: "My Awesome List"
                            elide: Label.ElideRight
                            horizontalAlignment: Qt.AlignHCenter
                            verticalAlignment: Qt.AlignVCenter
                            Layout.fillWidth: true
                        }
                        ToolButton {text: qsTr("⋮")}
                    }
                }
            
                //Dummy data model
                ListModel{
                    id: myModel
                    ListElement{number: 123; ip: "1.2.3.4"; status: "Idle"}
                    ListElement{number: 456; ip: "5.6.7.8"; status: "Idle"}
                    ListElement{number: 789; ip: "9.10.11.12"; status: "Run"}
                    ListElement{number: 101; ip: "13.14.15.16"; status: "Idle"}
                    ListElement{number: 213; ip: "192.168.1.1"; status: "Run"}
                }
            
                //List view
                ListView{
                    id: list
                    model: myModel
                    anchors.fill: parent
            
                    //Item delegate provides the "ripple" effect
                    delegate: ItemDelegate{
                        width: parent.width
                        //Some "hack" for alternating row colors as "Material.background: ..." doens't work
                        //See https://stackoverflow.com/questions/44889261/changing-background-and-text-color-of-a-itemdelegate
                        Component.onCompleted: background.color = (index % 2 == 0 ) ?
                                                   Material.background
                                                 : Qt.lighter(Material.background, 1.3)
            
                        //Simple row displaying data from model
                        Row{
                            anchors.verticalCenter: parent.verticalCenter
                            anchors.left: parent.left
                            anchors.leftMargin: 16
                            Label{width: 25; text: index}
                            Label{width: 50; text: number}
                            Label{width: 100; text: ip}
                            Label{width: 40; text: status}
                        }
                    }
                }
            }
            

            Note that to enable the "Material" theme, you need to place the file qtquickcontrols2.conf in the QML resource file (qml.qrc by default), which should already contains main.qml. The "ripple" effect is provided by ItemDelegate.

            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