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. [Solved] Change style property of QML element over event
Forum Updated to NodeBB v4.3 + New Features

[Solved] Change style property of QML element over event

Scheduled Pinned Locked Moved QML and Qt Quick
4 Posts 2 Posters 1.2k 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.
  • S Offline
    S Offline
    sf2212
    wrote on last edited by
    #1

    I have a component which displays a custom combo box:

    @ Column {
    anchors.top: parent.top
    anchors.topMargin: 200
    anchors.left: parent.left
    anchors.leftMargin: 30
    Rectangle {
    id: rectangle1
    signal comboClicked
    Column {
    id: column_button
    MenuButtonStyle {
    id: buttonCombo
    style: MyComboBoxButtonStyle {
    label: ButtonTextStyle {
    text: "Choose"
    }
    }
    }
    }
    Column {
    id: column1
    anchors.left: column_button.right
    anchors.leftMargin: -25
    anchors.top: parent.top
    anchors.topMargin: 3
    Image {
    id: image1
    width: 16
    source: "arrow_down.png"
    }
    }
    Keys.onReturnPressed: {
    rectangle1.state = rectangle1.state==="dropDown"?"":"dropDown"
    console.log("Open Drop Down..")
    }

            states: State {
                  name: "dropDown";
                  PropertyChanges { target: buttonCombo; style: MyButtonStyle }
            }
    
        }
    }@
    

    The goal is to change the style property in "MenuButtonStyle" module.

    I tried it with the line

    @PropertyChanges { target: buttonCombo; style: MyButtonStyle }@

    but it gives me the error:

    @file:///D:/projekte/qt_quick/FirstTest/MainPane.qml:82: ReferenceError: MyButtonStyle is not defined@

    If I replace the "MyComboBoxButtonStyle" directly with "MyButtonStyle" QT did not complain over a not defined reference.

    What is the problem? Is it not possible to change the style of a component like it is possible with CSS in HTML?

    1 Reply Last reply
    0
    • O Offline
      O Offline
      onek24
      wrote on last edited by
      #2

      Hello and welcome to devnet,

      It is not possible to set a Component via javascriptcode since i remember. You'll have to do something like that:
      @property Component myStyle: MyButtonStyle{}
      ...
      PropertyChanges { target: buttonCombo; style: myStyle}@

      That should theoretically work for you.

      1 Reply Last reply
      0
      • S Offline
        S Offline
        sf2212
        wrote on last edited by
        #3

        Yeah, works like a charm! Perfect! Many thanks for quick response.

        1 Reply Last reply
        0
        • O Offline
          O Offline
          onek24
          wrote on last edited by
          #4

          You're welcome, i'm glad that i could help 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