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. Qt Quick Controls 2: Same background, multiple buttons

Qt Quick Controls 2: Same background, multiple buttons

Scheduled Pinned Locked Moved Solved QML and Qt Quick
4 Posts 3 Posters 1.4k 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.
  • G Offline
    G Offline
    guy incognito
    wrote on last edited by
    #1

    Hi all,

    I got a few buttons and all got the same background. Now in every button there is this code:

    background: Rectangle{
        implicitHeight: x;
        implicitWidth: y;
        color: button.pressed ? "lightgray" : "white";
     }
    

    Is it possible, like in Qt Quick Controls, to define a single background rectangle and apply it to all buttons?

    E 1 Reply Last reply
    0
    • ODБOïO Offline
      ODБOïO Offline
      ODБOï
      wrote on last edited by
      #2

      Hi,
      You just have to create a new reusable file, exemple BackGround.qml (uppercase 'B ' is important to be able to reuse this component)

      like this :

      //Back.qml
      import QtQuick 2.0

      Rectangle {
      color :backMouse.pressed? "red" : "green"
      anchors.fill: parent
      MouseArea{
      id:backMouse
      anchors.fill: parent

      }
      

      }

      using :

      Button{
      text: "btn 3"
      background: Back{} // Back is our reusable component
      }

      i hope it helps you,

      LA

      1 Reply Last reply
      2
      • G guy incognito

        Hi all,

        I got a few buttons and all got the same background. Now in every button there is this code:

        background: Rectangle{
            implicitHeight: x;
            implicitWidth: y;
            color: button.pressed ? "lightgray" : "white";
         }
        

        Is it possible, like in Qt Quick Controls, to define a single background rectangle and apply it to all buttons?

        E Offline
        E Offline
        Eeli K
        wrote on last edited by
        #3

        @guy-incognito Either what LeLev said, or you can make a custom Button component and reuse that. If there are many customized but identical parts in your buttons it makes sense to customize the whole Button, otherwise it's reasonable to customize only the background.

        This is actually a very common thing in Controls 2, everything is customized that way. Each type's documentation has also "Customizing X" link.

        1 Reply Last reply
        1
        • G Offline
          G Offline
          guy incognito
          wrote on last edited by
          #4

          Thanks to both of you!

          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