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 can I create an image like layout with QML ?

How can I create an image like layout with QML ?

Scheduled Pinned Locked Moved Unsolved QML and Qt Quick
6 Posts 2 Posters 1.1k 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.
  • J Offline
    J Offline
    Janilson Duarte
    wrote on 10 Jan 2019, 13:56 last edited by
    #1

    I'm learning QML now and I want to create something like the attached image, I've already tried to create something but I can not manipulate the vertical menu buttons and leave the image equal, could someone show me what I should do?

    0_1547128291384_template.png

    import QtQuick 2.9
    import QtQuick.Window 2.2
    
    import QtQuick.Controls 1.4
    import QtQuick.Controls.Styles 1.4
    import QtQuick.Layouts 1.11
    import QtCharts 2.0
    
     Window {
            visible: true
            width: 640
            height: 480
            title: qsTr("Hello World")
    
            color: "gainsboro"
    
            Rectangle {
                id: page
                width: 320; height: 1020
                color: "navy"
    
                Text {
                    id: helloText
                    y: 30
                    anchors.horizontalCenter: page.horizontalCenter
                    font.pointSize: 24; font.bold: true
                }
    
     Button {
                    text: "button"
                    style: ButtonStyle {
                        background: Rectangle {
                            implicitWidth: 321
                            implicitHeight: 25
                            border.width: control.activeFocus ? 2 : 1
                            border.color: "#fff"
                            radius: 0
                            gradient: Gradient {
                                GradientStop { position: 0 ; 
    color: control.pressed ? "#ccc" : "deepskyblue" }
                                GradientStop { position: 1 ; 
    color: control.pressed ? "#aaa" : "deepskyblue" }
                            }
                        }
                    }
                }
            }
    
    Item {
                        x: 520; y: 50;
                        width: 300; height: 100
    
                        Row { 
                            spacing: 20 
                            Rectangle { width: 300; height: 100; color: "white" }
                            Rectangle { width: 300; height: 100; color: "white" }
                            Rectangle { width: 300; height: 100; color: "white" }
                            Rectangle { width: 300; height: 100; color: "white" }
                        }
    
                        Row { 
                            spacing: 20
                            x: 0; y: 220;
    
                            Rectangle { width: 300; height: 100; color: "white" }
                            Rectangle { width: 300; height: 100; color: "white" }
                            Rectangle { width: 300; height: 100; color: "white" }
                            Rectangle { width: 300; height: 100; color: "white" }
                        }
                    }
        }    
    
    1 Reply Last reply
    0
    • O Offline
      O Offline
      ODБOï
      wrote on 10 Jan 2019, 17:27 last edited by ODБOï 1 Oct 2019, 17:35
      #2

      Hi @Janilson-Duarte,

      Window {
          visible: true
          width: 640
          height: 480
          title: qsTr("Hello World")
          id:wn
          color: "gainsboro"
          //page
          RowLayout{
              anchors.fill: parent
              // left navigation menu
              ColumnLayout{
                  //Layout.maximumHeight: 100
                  //Layout.maximumWidth: 100
                  //Layout.minimumHeight: 50
                  //Layout.minimumWidth: 50
                  Text{text:"Menu";font.bold: true;font.pixelSize: 15;Layout.alignment: Qt.AlignCenter}
                  Repeater{
                      model: 5
                      Button{
                          text:"menu btn " + index
                          Layout.fillHeight: true
                          Layout.fillWidth: true
                      }
                  }
      
              }
      
              // shown page content(white Rectangles)
              GridLayout{
                  columns: 2
      
                  Repeater{
                      model:4
                      Rectangle{
                          color: "white"
                          Layout.fillHeight: true
                          Layout.fillWidth: true
                          Layout.preferredHeight: 100
                          Layout.preferredWidth: 100
      
                          Text{text: "menu item " + index;anchors.centerIn: parent}
                      }
                  }
              }
          }
      
      }
      

      In this page there is all you need to master positioning with QML

      1 Reply Last reply
      2
      • J Offline
        J Offline
        Janilson Duarte
        wrote on 11 Jan 2019, 11:14 last edited by
        #3

        @LeLev Thanks for help, but you know how i can do a vertical menu with icons like that?

        O 1 Reply Last reply 11 Jan 2019, 11:46
        0
        • J Janilson Duarte
          11 Jan 2019, 11:14

          @LeLev Thanks for help, but you know how i can do a vertical menu with icons like that?

          O Offline
          O Offline
          ODБOï
          wrote on 11 Jan 2019, 11:46 last edited by
          #4

          @Janilson-Duarte
          several possibilities, one is to create your custom Component

          Rectangle{
           RowLayout{
             Image{} 
             Text{}
           }
          MouseArea{}
          }
          
          1 Reply Last reply
          1
          • J Offline
            J Offline
            Janilson Duarte
            wrote on 11 Jan 2019, 15:04 last edited by
            #5

            @LeLev Thanks a lot, now I want to know how to make a tabview vertical menu with icons?

            Can you help me again?

            I tried this

            TabView {
                Tab {
                    title: "Red"
                    RowLayout{
                      Image{ source: "img/image.png"}
                 }
            
                }
                
                Tab {
                    title: "Blue"
                    Rectangle { color: "blue" }
                }
                Tab {
                    title: "Green"
                    Rectangle { color: "green" }
                }
            }
            
            1 Reply Last reply
            0
            • O Offline
              O Offline
              ODБOï
              wrote on 11 Jan 2019, 21:59 last edited by
              #6

              can this help ? https://forum.qt.io/topic/81323/how-can-i-create-vertical-tab-view-in-qml

              1 Reply Last reply
              2

              4/6

              11 Jan 2019, 11:46

              • Login

              • Login or register to search.
              4 out of 6
              • First post
                4/6
                Last post
              0
              • Categories
              • Recent
              • Tags
              • Popular
              • Users
              • Groups
              • Search
              • Get Qt Extensions
              • Unsolved