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. foreground property with QML Button
Forum Updated to NodeBB v4.3 + New Features

foreground property with QML Button

Scheduled Pinned Locked Moved Unsolved QML and Qt Quick
buttonqmlforeground
3 Posts 3 Posters 585 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
    Reddy_12
    wrote on last edited by
    #1

    Hello,

    I want to apply a columlayout to the QML button using foreground property. Based on the content i read from internet and QML documentations, i have developed the below example.

    import QtQuick 2.15
    import QtQuick.Window 2.2
    import QtQuick.Controls 2.15
    import QtQuick.Layouts 1.3
    
    Window {
        visible: true
        width: 640
        height: 480
        title: qsTr("Hello World")
    
        Button {
            id: myButton
            text: "Click Me"
            foreground:ColumnLayout{
                anchors.fill: parent
                Rectangle{
                    id:rect1
                    Text{
                        text: "Rect1"
                    }
                }
                Rectangle{
                    id:rect2
                    Text{
                        text: "Rect2"
                    }
                }
            }
            onClicked: {
                myButton.foreground.visible = !myButton.foreground.visible; // toggle visibility of foreground
            }
        }
    }
    

    When i am trying to exevute i am facing the following error.

    "cannot assign to non-existent property foreground", the versions that i am importing are QtQuick 2.15 & QtQuick.Controls.2.15

    I know that there is a foreground property in Materials module of QML for changing color, but i wanted something like mentioned above.

    Any help for the same will be helpful.

    Thanks,

    JoeCFDJ 1 Reply Last reply
    0
    • R Reddy_12

      Hello,

      I want to apply a columlayout to the QML button using foreground property. Based on the content i read from internet and QML documentations, i have developed the below example.

      import QtQuick 2.15
      import QtQuick.Window 2.2
      import QtQuick.Controls 2.15
      import QtQuick.Layouts 1.3
      
      Window {
          visible: true
          width: 640
          height: 480
          title: qsTr("Hello World")
      
          Button {
              id: myButton
              text: "Click Me"
              foreground:ColumnLayout{
                  anchors.fill: parent
                  Rectangle{
                      id:rect1
                      Text{
                          text: "Rect1"
                      }
                  }
                  Rectangle{
                      id:rect2
                      Text{
                          text: "Rect2"
                      }
                  }
              }
              onClicked: {
                  myButton.foreground.visible = !myButton.foreground.visible; // toggle visibility of foreground
              }
          }
      }
      

      When i am trying to exevute i am facing the following error.

      "cannot assign to non-existent property foreground", the versions that i am importing are QtQuick 2.15 & QtQuick.Controls.2.15

      I know that there is a foreground property in Materials module of QML for changing color, but i wanted something like mentioned above.

      Any help for the same will be helpful.

      Thanks,

      JoeCFDJ Offline
      JoeCFDJ Offline
      JoeCFD
      wrote on last edited by JoeCFD
      #2

      @Reddy_12 no definition for foreground in button. Check here out
      https://doc.qt.io/qt-5.15/qml-qtquick-controls2-button-members.html

      GrecKoG 1 Reply Last reply
      0
      • JoeCFDJ JoeCFD

        @Reddy_12 no definition for foreground in button. Check here out
        https://doc.qt.io/qt-5.15/qml-qtquick-controls2-button-members.html

        GrecKoG Offline
        GrecKoG Offline
        GrecKo
        Qt Champions 2018
        wrote on last edited by
        #3

        @JoeCFD Layouts are visual items...

        1 Reply Last reply
        2

        • Login

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