How to connect Text widget to Customised Combo Box (QML -code)

In this project the customised combo Box action linked with
Text widget of the Flipabit.
Steps in Customised ComboBox:

  1. Open a new project: File > New
  2. Add new Component: Widgets>Component>Create new
  3. Add Text Widget : Widgets> T Text
    (Name it as Txt in Widget Tree and Change Text properties in Font in Widget Inspector)
  4. Add Code to the Component 1.
    Select Component 1 in Widget Tree > Click on Actions (<> Actions)> Click on Code icon(# Code) in the main menu bar
  5. Paste Code in the Code Editor: 4th step action opens
    code Editor window> Click + icon > Click cursor beside 1
    in editor> Paste the Copied code in the edotor.
  6. Save the Code: Click on the Page > In the pop up window
    click on Yes Button.
  7. Run the project: Run>Preview
    The code for ComboBox in QML:
    import QtQuick 2.15
    import QtQuick.Controls 2.15
    Item{
    ComboBox {
    id: comboBox
    width: 200
    model: [“Option 0”,“Option 1”, “Option 2”, “Option 3” ,“Option 4”, “Option 5”, “Option 6”,“Option 7”, “Option 8”,“Option 9”,“Option 10”, “Option 11”, “Option 12”]
    onCurrentTextChanged: {
    document.childByName(“Txt”).content.scriptAdaptor.actionSetText("Index : “+ comboBox.currentIndex +”
    "+ "Text : "+ comboBox.currentText)
    }
    }
    }

    ComboBox Customised with Text Widget.flp (5.8 KB)
2 Likes

Для написания кода используйте специальный тег
To write code, use a special tag
2024-12-17_20-19-05

import QtQuick 2.15
import QtQuick.Controls 2.15
Item{
    ComboBox {
    id: comboBox 
    width: 200
    model: ["Option 0","Option 1", "Option 2", "Option 3" ,"Option 4", "Option 5", "Option 6","Option 7", "Option 8","Option 9","Option 10", "Option 11", "Option 12"]
    onCurrentTextChanged: {
        document.childByName("Txt").content.scriptAdaptor.actionSetText("Index : "+ comboBox.currentIndex +"
"+ "Text : "+ comboBox.currentText)
    }//Action
     }//ComboBox
} // item

Back to Flipabit >
Copyright © 2018. Flipabit Team. All rights reserved.