QML reset dialog with tabview

Adar Malik

I was trying to implement a tabbed Dialog in QML with the means to reset it to the intial values.

Since tabs are dynamically instantiated, none of the straight forward methods seem to work. The parent Dialog can not reference the inner Combobox and the Combobox can not reference the outer Dialog. How can this be achieved?

import QtQuick 2.3
import QtQuick.Controls 1.4
import QtQuick.Dialogs 1.2
import QtQuick.Layouts 1.1

Dialog {
    id: dlg
    title: "Settings"
    visible: true
    standardButtons: StandardButton.Apply | StandardButton.Reset
    property string val: ""
    onApply: console.log(val)
    onReset: {
        // RESET COMBOBOX TO DEFAULT
    }
    TabView {
        id: tabView
        anchors.fill: parent
        Tab {
            title: "ValueTab"
            id: tabVal
            GridLayout {
                id: gridVal
                anchors.fill: parent
                GroupBox {
                    title: qsTr("Choose value")
                    id: gb
                    Layout.fillWidth: true
                    ColumnLayout {
                        anchors.fill: parent
                        id: cl
                        ComboBox {
                            id: valueChooser
                            editable: false
                            model: ListModel {
                                id: listModel
                                ListElement { text: "One" }
                                ListElement { text: "Two" }
                                ListElement { text: "Three" }
                            }
                            Layout.fillWidth: true
                            onCurrentTextChanged : val = currentText
                        }
                    }
                }
            }
        }
    }
}
derM

I am quite unsure, if I got your question right as you say, you can not reference the Dialog from within the Combobox. I can not see the reason why.

Assuming the example of yours contains indeed your problem and all you want to do is to reset the values (and you know the original values) once the reset button is pressed, this is how I would solve it.
Using the Connections-type to connect to the Dialog's reset() from within the Combobox

import QtQuick 2.3
import QtQuick.Controls 1.4
import QtQuick.Dialogs 1.2
import QtQuick.Layouts 1.1

Dialog {
    id: dlg
    title: "Settings"
    visible: true
    standardButtons: StandardButton.Apply | StandardButton.Reset
    property string val: ""
    onApply: console.log(val)
    onReset: {
        // **DONT** RESET COMBOBOX TO DEFAULT **HERE**
    }
    TabView {
        id: tabView
        anchors.fill: parent
        Tab {
            title: "ValueTab"
            id: tabVal
            GridLayout {
                id: gridVal
                anchors.fill: parent
                GroupBox {
                    title: qsTr("Choose value")
                    id: gb
                    Layout.fillWidth: true
                    ColumnLayout {
                        anchors.fill: parent
                        id: cl
                        ComboBox {
                            id: valueChooser
                            editable: false
                            model: ListModel {
                                id: listModel
                                ListElement { text: "One" }
                                ListElement { text: "Two" }
                                ListElement { text: "Three" }
                            }
                            Layout.fillWidth: true
                            onCurrentTextChanged : val = currentText

                            /// *** INTERESTING PART HERE! ***
                            Connections {
                                target: dlg
                                onReset: {
                                    // RESET COMBOBOX TO DEFAULT **HERE** INSTEAD
                                    valueChooser.currentIndex = 0
                                }
                            }
                        }
                    }
                }
            }
        }
    }
}

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

From Dev

qml How to use loader within tabview

From Dev

Change Tab programatically in TabView Qt QML

From Dev

QML Dialog with focused textField

From Dev

Fixed size for QML Dialog

From Dev

Fixed size for QML Dialog

From Dev

Call function or property in another QML File inside a TabView in QML

From Dev

How to force active focus/select QML Tab under QML TabView?

From Dev

QML ListView is not updated on model reset

From Dev

Titanium Android Option dialog reset

From Dev

p:tabView restting after opening a p:dialog from one of the tabs

From Dev

QML: How to reset item property to defaut

From Dev

How to change the transient parent of a QML Dialog/Window?

From Dev

Embed QML Dialog inside QDialog window at runtime

From Dev

How to change behaviour of Enter key in QML Dialog?

From Dev

How to change the transient parent of a QML Dialog/Window?

From Dev

Reset Open File Dialog Position in Windows

From Dev

jQuery UI: how to reset dialog title?

From Dev

How to add reset button in Dialog box

From Dev

QT 5.7 QML How to control which Control gets the focus within a TabView

From Dev

Reset "<App> would like to access your photos" dialog on iOS

From Dev

The Dialog Form remembers last button focus. How to reset it?

From Dev

The Dialog Form remembers last button focus. How to reset it?

From Dev

How to create a message dialog using QML Control elements(such as combobox, textfield, checkbox..)

From Java

A fragment-based Dialog is not destroyed/reset in UI5 upon leaving the view

From Dev

Tabview content is overlapped

From Dev

qooxdoo tabview steals focus

From Dev

Dynamic tabs in TabView nativescript

From Dev

How child of tabview can access elements of view which holds tabview?

From Dev

Required fields within a p:tabView

Related Related

  1. 1

    qml How to use loader within tabview

  2. 2

    Change Tab programatically in TabView Qt QML

  3. 3

    QML Dialog with focused textField

  4. 4

    Fixed size for QML Dialog

  5. 5

    Fixed size for QML Dialog

  6. 6

    Call function or property in another QML File inside a TabView in QML

  7. 7

    How to force active focus/select QML Tab under QML TabView?

  8. 8

    QML ListView is not updated on model reset

  9. 9

    Titanium Android Option dialog reset

  10. 10

    p:tabView restting after opening a p:dialog from one of the tabs

  11. 11

    QML: How to reset item property to defaut

  12. 12

    How to change the transient parent of a QML Dialog/Window?

  13. 13

    Embed QML Dialog inside QDialog window at runtime

  14. 14

    How to change behaviour of Enter key in QML Dialog?

  15. 15

    How to change the transient parent of a QML Dialog/Window?

  16. 16

    Reset Open File Dialog Position in Windows

  17. 17

    jQuery UI: how to reset dialog title?

  18. 18

    How to add reset button in Dialog box

  19. 19

    QT 5.7 QML How to control which Control gets the focus within a TabView

  20. 20

    Reset "<App> would like to access your photos" dialog on iOS

  21. 21

    The Dialog Form remembers last button focus. How to reset it?

  22. 22

    The Dialog Form remembers last button focus. How to reset it?

  23. 23

    How to create a message dialog using QML Control elements(such as combobox, textfield, checkbox..)

  24. 24

    A fragment-based Dialog is not destroyed/reset in UI5 upon leaving the view

  25. 25

    Tabview content is overlapped

  26. 26

    qooxdoo tabview steals focus

  27. 27

    Dynamic tabs in TabView nativescript

  28. 28

    How child of tabview can access elements of view which holds tabview?

  29. 29

    Required fields within a p:tabView

HotTag

Archive