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
QtWS25 Last Chance

foreground property with QML Button

Scheduled Pinned Locked Moved Unsolved QML and Qt Quick
buttonqmlforeground
3 Posts 3 Posters 562 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 13 Mar 2023, 06:49 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,

    J 1 Reply Last reply 13 Mar 2023, 14:27
    0
    • R Reddy_12
      13 Mar 2023, 06:49

      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,

      J Offline
      J Offline
      JoeCFD
      wrote on 13 Mar 2023, 14:27 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

      G 1 Reply Last reply 14 Mar 2023, 14:38
      0
      • J JoeCFD
        13 Mar 2023, 14:27

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

        G Offline
        G Offline
        GrecKo
        Qt Champions 2018
        wrote on 14 Mar 2023, 14:38 last edited by
        #3

        @JoeCFD Layouts are visual items...

        1 Reply Last reply
        2

        2/3

        13 Mar 2023, 14:27

        • Login

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