Is there a way to create an empty grid inside a QML GridLayout? - qml

I am trying to create a periodic table using QML. In order to arrange the elements properly (I use GroupBoxes) , I need to have blank space/empty grids. I already tried inserting empty Items into the desired grids but the GridLayout would just ignore them. Using empty GroupBoxes leads to little squares being left at the position where nothing is supposed to be.
Yet my Code looks like this:
GridLayout {
id: grid
anchors.fill: parent //grid erstreckt sich nun über ganzes Window
columns: 18
rows: 9
GroupBox {
//GroupBoxen werden maximal gestreckt in Höhe und Breite --> raum wird ausgefüllt
Layout.fillHeight: true
Layout.fillWidth: true
ColumnLayout {
Label {
Layout.alignment: Qt.AlignLeft
text: qsTr("1")
}
Label {
Layout.alignment: Qt.AlignHCenter
text: qsTr("H")
}
Label {
Layout.alignment: Qt.AlignHCenter
text: qsTr("Hydrogen")
}
}
}
Repeater {
model: 16
GroupBox {
}
}
GroupBox {
//GroupBoxen werden maximal gestreckt in Höhe und Breite --> raum wird ausgefüllt
Layout.fillHeight: true
Layout.fillWidth: true
ColumnLayout {
Label {
Layout.alignment: Qt.AlignLeft
text: qsTr("1")
}
Label {
Layout.alignment: Qt.AlignHCenter
text: qsTr("H")
}
Label {
Layout.alignment: Qt.AlignHCenter
text: qsTr("Hydrogen")
}
}
}
Repeater {
model: 100
GroupBox {
//GroupBoxen werden maximal gestreckt in Höhe und Breite --> raum wird ausgefüllt
Layout.fillHeight: true
Layout.fillWidth: true
ColumnLayout {
Label {
Layout.alignment: Qt.AlignLeft
text: qsTr("1")
}
Label {
Layout.alignment: Qt.AlignHCenter
text: qsTr("H")
}
Label {
Layout.alignment: Qt.AlignHCenter
text: qsTr("Hydrogen")
}
}
}
}
Which lead to my application looking like this:
PeriodicTable qml

You can set the background of your placeholder GroupBox to be an Item like this
Repeater {
model: 16
GroupBox {
background: Item {}
}
}
or you could just use an Item directly like this
Repeater {
model: 16
Item {}
}

Related

PropertyAnimation does not fire

I have QML element consisting of transparent Rectangle and Image inside of it. The purpose of this element is to show some operation success - if some operation was executed successfully, checkmark icons pops up and then slowly dissapears in time of 1000ms.
Here is the simplified code that should done this job:
import QtQuick 2.5
import QtQuick.Layouts 1.1
Rectangle
{
id: ueActionResultIndicator
property bool ueParamConnectionOk: false
width: 128
height: 128
color: "transparent"
ColumnLayout
{
anchors.fill: parent
Image
{
Layout.fillWidth: true
Layout.fillHeight: true
horizontalAlignment: Qt.AlignHCenter
verticalAlignment: Qt.AlignVCenter
smooth: true
fillMode: Image.PreserveAspectFit
// source: ueParamConnectionOk===true?"qrc:///ueIcons/icons/ueActionOk.png"
// :"qrc:///ueIcons/icons/ueActionCancel.png"
source: "http://www.clker.com/cliparts/0/f/7/0/11954234311954389563ok_mark_h_kon_l_vdal_02.svg.hi.png"
} // Image
} // ColumnLayout
states:
[
State
{
name: "ueStateHidden"
PropertyChanges
{
target: ueActionResultIndicator
opacity: 0.00
} // PropertyChanges
}, // State
State
{
name: "ueStateShown"
PropertyChanges
{
target: ueActionResultIndicator
opacity: 1.00
} // PropertyChanges
} // State
] // states
transitions:
[
Transition
{
from: "ueStateShown"
to: "ueStateHidden"
PropertyAnimation
{
properties: "opacity"
duration: 1000
loops: 3
easing.type: Easing.InOutSine
onStarted:
{
visible=true;
enabled=true;
} // onStarted
onStopped:
{
visible=false;
enabled=false;
} // onStopped
} // PropertyAnimation
} // Transition
] // transitions
Component.onCompleted:
{
state="ueStateHidden";
} // Component.onCompleted
} // Rectangle
and here is parent .QML file triggering it:
import QtQuick 2.5
import QtQuick.Controls 1.4
import QtQuick.Layouts 1.1
import QtQuick.Window 2.2
import QtQuick.Controls.Styles 1.4
Window
{
width: 512
height: 512
flags: Qt.FramelessWindowHint
visible: true
ColumnLayout
{
anchors.fill: parent
spacing: 8
Rectangle
{
Layout.fillWidth: true
Layout.fillHeight: true
Layout.margins: 8
radius: 16
border.color: "#4682b4"
border.width: 1
antialiasing: true
gradient: Gradient
{
GradientStop
{
position: 0
color: "#636363"
} // GradientStop
GradientStop
{
position: 1
color: "#303030"
} // GradientStop
} // Gradient
ColumnLayout
{
anchors.fill: parent
RowLayout
{
spacing: 8
Layout.fillWidth: true
Layout.fillHeight: true
Layout.margins: 8
Layout.alignment: Qt.AlignHCenter|Qt.AlignTop
antialiasing: true
Text
{
text: qsTr("APPLICATION SETTINGS")
clip: true
font.bold: true
font.pointSize: 24
textFormat: Text.RichText
verticalAlignment: Text.AlignVCenter
horizontalAlignment: Text.AlignHCenter
} // Text
} // RowLayout
ColumnLayout
{
Layout.fillWidth: true
Layout.fillHeight: true
Layout.margins: 8
Layout.alignment: Qt.AlignHCenter|Qt.AlignBottom
TabView
{
Layout.fillWidth: true
Layout.fillHeight: true
Layout.alignment: Qt.AlignHCenter|Qt.AlignVCenter
frameVisible: true
Tab
{
asynchronous: true
title: qsTr("Database")
Layout.fillWidth: true
Layout.fillHeight: true
Layout.alignment: Qt.AlignHCenter|Qt.AlignVCenter
ColumnLayout
{
spacing: 8
Layout.fillWidth: true
Layout.fillHeight: true
Layout.alignment: Qt.AlignHCenter|Qt.AlignVCenter
TextField
{
id: textFieldServerAddress
antialiasing: true
Layout.fillWidth: true
Layout.fillHeight: false
placeholderText: qsTr("database server address")
} // TextField
TextField
{
id: textFieldServerPort
Layout.fillWidth: true
Layout.fillHeight: false
placeholderText: qsTr("database server port")
} // TextField
TextField
{
id: textFieldDatabaseName
Layout.fillWidth: true
Layout.fillHeight: false
placeholderText: qsTr("database name")
} // TextField
TextField
{
id: textFieldDatabaseUsername
Layout.fillWidth: true
Layout.fillHeight: false
placeholderText: qsTr("database access username")
} // TextField
TextField
{
id: textFieldDatabasePassword
Layout.fillWidth: true
Layout.fillHeight: false
placeholderText: qsTr("database access password")
echoMode: TextInput.PasswordEchoOnEdit
} // TextField
RowLayout
{
Layout.fillWidth: true
Layout.fillHeight: false
Layout.alignment: Qt.AlignLeft|Qt.AlignVCenter
spacing: 8
Button
{
Layout.fillWidth: false
Layout.fillHeight: true
Layout.alignment: Qt.AlignLeft|Qt.AlignVCenter
text: qsTr("Test Connection")
onClicked:
{
ueActionResultIndicator.state="ueStateShown";
} // onClicked
} // Button
} // RowLayout
} // ColumnLayout
} // Tab
} // TabView
} // ColumnLayout
} // ColumnLayout
} // Rectangle
} // ColumnLayout
UeActionResultIndicator
{
id: ueActionResultIndicator
} // UeActionResultIndicator
} // Window
Why the checkmark once shown does not slowly dissapear, i.e., why does PropertyAnimation not get started?
You only shown Image.
ueActionResultIndicator.state = "ueStateShown";
For disappear you must add
ueActionResultIndicator.state = "ueStateHidden"
But, anyway, i think, you must refactor this code and run animation from function without states:
Rectangle {
id: rect
width: 100
height: 62
color: "green"
PropertyAnimation
{
id: opacityAnimation
properties: "opacity"
target: rect
from: 0.0
to: 1.0
duration: 1000
loops: 3
easing.type: Easing.InOutSine
onStarted:
{
visible=true;
enabled=true;
} // onStarted
onStopped:
{
visible=false;
enabled=false;
} // onStopped
} // PropertyAnimation
function runAnimation() {
opacityAnimation.running = true
}
}

saving data from TextField type ListView delegate into property

I have a QML Window with ListView inside TabView's Tab, which
delegates are instances of TextField:
import QtQuick 2.5
import QtQuick.Controls 1.4
import QtQuick.Layouts 1.1
import QtQuick.Window 2.2
import QtQuick.Controls.Styles 1.4
Window
{
width: Screen.width/2
height: Screen.height/2
x: Screen.width/2-width/2
y: Screen.height/2-height/2
flags: Qt.FramelessWindowHint
visible: true
color: "transparent"
property string uePropertyServerAddress:""
property string uePropertyServerPort:""
property string uePropertyDatabaseName:""
property string uePropertyDatabaseUsername:""
property string uePropertyDatabasePassword:""
property string uePropertyHostname:""
ColumnLayout
{
anchors.fill: parent
spacing: 8
Rectangle
{
Layout.fillWidth: true
Layout.fillHeight: true
Layout.margins: 8
radius: 16
border.color: "#4682b4"
border.width: 1
antialiasing: true
gradient: Gradient
{
GradientStop
{
position: 0
color: "#636363"
} // GradientStop
GradientStop
{
position: 1
color: "#303030"
} // GradientStop
} // Gradient
ColumnLayout
{
anchors.fill: parent
RowLayout
{
spacing: 8
Layout.fillWidth: true
Layout.fillHeight: true
Layout.margins: 8
Layout.alignment: Qt.AlignHCenter|Qt.AlignTop
antialiasing: true
Text
{
text: qsTr("APPLICATION SETTINGS")
clip: true
font.bold: true
font.pointSize: 24
textFormat: Text.RichText
verticalAlignment: Text.AlignVCenter
horizontalAlignment: Text.AlignHCenter
} // Text
} // RowLayout
ColumnLayout
{
Layout.fillWidth: true
Layout.fillHeight: true
Layout.margins: 8
Layout.alignment: Qt.AlignHCenter|Qt.AlignBottom
TabView
{
Layout.fillWidth: true
Layout.fillHeight: true
Layout.alignment: Qt.AlignHCenter|Qt.AlignVCenter
tabPosition: Qt.TopEdge
frameVisible: true
style: TabViewStyle
{
frameOverlap: 1
tab: Rectangle
{
implicitWidth: 128//Math.max(ueTabText.width+4, 120)
implicitHeight: 48//ueTabText.height*2
radius: 8
border.color: "#4682b4"
border.width: 1
gradient: Gradient
{
GradientStop
{
position: 0
color: "#ffffff"
} // GradientStop
GradientStop
{
position: 0.418
color: styleData.selected ? "steelblue" : "#000000"
} // GradientStop
} // gradient
ColumnLayout
{
anchors.fill:parent
Text
{
id: ueTabText
Layout.fillWidth: true
Layout.fillHeight: true
Layout.margins: 8
text: styleData.title
color: styleData.selected?"black":"white"
} // Text
} // ColumnLayout
} // tab
frame: Rectangle
{
radius: 8
border.color: "#4682b4"
border.width: 1
color: "black"
} // frame
} // TabViewStyle
Tab
{
asynchronous: true
title: qsTr("Database")
Layout.fillWidth: true
Layout.fillHeight: true
Layout.alignment: Qt.AlignHCenter|Qt.AlignVCenter
ColumnLayout
{
spacing: 8
Layout.fillWidth: true
Layout.fillHeight: true
Layout.alignment: Qt.AlignHCenter|Qt.AlignVCenter
ListModel
{
id: ueDatabaseSettingsModel
ListElement
{
feature: qsTr("database server address")
} // ListElement
ListElement
{
feature: qsTr("database server port")
} // ListElement
ListElement
{
feature: qsTr("database name")
} // ListElement
ListElement
{
feature: qsTr("database access username")
} // ListElement
ListElement
{
feature: qsTr("database access password")
} // ListElement
} // ListModel
ListView
{
id: ueDatabaseSettingListView
Layout.fillWidth: true
Layout.fillHeight: true
Layout.alignment: Qt.AlignHCenter|Qt.AlignVCenter
Layout.margins: 8
spacing: 16
delegate: TextField
{
width: ueDatabaseSettingListView.width
antialiasing: true
placeholderText: model.feature
style: TextFieldStyle
{
textColor: "#C1C1C1"
placeholderTextColor: "steelblue"
background: Rectangle
{
color: "#323232"
border.color: "#4682b4"
border.width: 1
}
} // TextFieldStyle
} // delegate
Component.onCompleted:
{
model=ueDatabaseSettingsModel;
} // Component.OnCompleted
} // ListView
} // ColumnLayout
} // Tab
} // TabView
RowLayout
{
Layout.fillWidth: true
Layout.fillHeight: false
Layout.alignment: Qt.AlignLeft|Qt.AlignVCenter
spacing: 8
Button
{
Layout.fillWidth: false
Layout.fillHeight: true
Layout.alignment: Qt.AlignLeft|Qt.AlignVCenter
text: qsTr("Apply")
onClicked:
{
} // onClicked
} // Button
Button
{
Layout.fillWidth: false
Layout.fillHeight: true
Layout.alignment: Qt.AlignLeft|Qt.AlignVCenter
text: qsTr("Clear")
onClicked:
{
} // onUeSignalButtonClicked
} // Button
} // RowLayout
} // ColumnLayout
} // ColumnLayout
} // Rectangle
} // ColumnLayout
} // Window
This works just fine, but I've stumbled across problem of saving TextField's values into GUI item properties:
TextField database server address must save value into property string uePropertyServerAddress
TextField database server port must save value into property string uePropertyServerPort
etc ... for all other TextFields.
The question is, how do I "link" delegates of ListView (TextField instances) to belonging property?
I think you need to refactor as BaCaRoZzo commented, but I think the problem could be solved with minimum change.
First, append target property name into each ListElement
ListModel
{
id: ueDatabaseSettingsModel
ListElement
{
feature: qsTr("database server address")
target: "uePropertyServerAddress"
} // ListElement
ListElement
{
feature: qsTr("database server port")
target: "uePropertyServerPort"
} // ListElement
ListElement
{
feature: qsTr("database name")
target: "uePropertyDatabaseName"
} // ListElement
ListElement
{
feature: qsTr("database access username")
target: "uePropertyDatabaseUsername"
} // ListElement
ListElement
{
feature: qsTr("database access password")
target: "uePropertyDatabasePassword"
} // ListElement
} // ListModel
Second, add onEditingFinished handler like the following
delegate: TextField
{
...
onEditingFinished: {
window[model.target] = text;
}
}
Third, add id to Window to access its properties
Window
{
id: window
Then you can see each TextField's text is assigned to the property.

Rectangle's MouseArea.onClicked on first mouse click state property empty

I have following QML Rectangle:
import QtQuick 2.5
import QtQuick.Layouts 1.1
Rectangle
{
id: uePlaceSwitcher
property string ueParamUserImage
property string ueParamUserName
property string ueParamPlaceName
signal ueSignalPlaceSwitcherReleased
signal ueSignalPlaceSwitcherPressed
radius: 16
border.color: "#4682b4"
border.width: 1
antialiasing: true
Layout.fillWidth: true
Layout.fillHeight: true
Layout.minimumWidth: 128
Layout.preferredWidth: 384
Layout.maximumWidth: 384
enabled: false
gradient: Gradient
{
GradientStop
{
id: uePlaceSwitcherGradientPosition0
position: 0
color: "#000000"
ParallelAnimation on color
{
id: uePlaceSwitcherReleasedAnimation
loops: 1
running: false
ColorAnimation
{
from: "#4682b4"
to: "#000000"
duration: 100
} // ColorAnimation
} // ParallelAnimation
ParallelAnimation on color
{
id: uePlaceSwitcherPressedAnimation
loops: 1
running: false
ColorAnimation
{
from: "#000000"
to: "#4682b4"
duration: 100
} // ColorAnimation
} // ParallelAnimation
} // GradientStop
GradientStop
{
id: uePlaceSwitcherGradientPosition1
position: 1
color: "#ffffff"
} // GradientStop
} // Gradient
RowLayout
{
id: ueMainLayout
anchors.fill: parent
anchors.margins: 8
spacing: 8
Image
{
id: ueUserImage
antialiasing: true
clip: true
Layout.fillWidth: true
Layout.fillHeight: true
Layout.alignment: Qt.AlignLeft|Qt.AlignVCenter
source: ueParamUserImage
smooth: true
fillMode: Image.PreserveAspectFit
horizontalAlignment: Image.AlignHCenter
verticalAlignment: Image.AlignVCenter
} // Image
ColumnLayout
{
Layout.fillWidth: true
Layout.fillHeight: true
Layout.alignment: Qt.AlignLeft|Qt.AlignVCenter
Text
{
color: "#ffffff"
Layout.fillWidth: true
Layout.fillHeight: true
Layout.alignment: Qt.AlignLeft|Qt.AlignTop
antialiasing: true
text: ueParamUserName
font.family: "Courier"
font.bold: true
font.pointSize: 16
clip: true
textFormat: Text.RichText
verticalAlignment: Text.AlignVCenter
horizontalAlignment: Text.AlignHCenter
} // Text
Text
{
color: "#ffffff"
Layout.fillWidth: true
Layout.fillHeight: true
Layout.alignment: Qt.AlignLeft|Qt.AlignBottom
antialiasing: true
text: ueParamPlaceName
font.family: "Courier"
font.bold: true
font.pointSize: 16
clip: true
textFormat: Text.RichText
verticalAlignment: Text.AlignVCenter
horizontalAlignment: Text.AlignHCenter
} // Text
} // ColumnLayout
} // RowLayout
MouseArea
{
anchors.fill: parent
onClicked:
{
print("onClicked state: "+state)
if(state==="uePlaceSwitcherStateReleased")
{
state="uePlaceSwitcherStatePressed"
uePlaceSwitcherPressedAnimation.running=true
ueSignalPlaceSwitcherPressed()
}
else
{
state="uePlaceSwitcherStateReleased"
uePlaceSwitcherReleasedAnimation.running=true
ueSignalPlaceSwitcherReleased()
} // if
} // onClicked
} // MouseArea
states:
[
State
{
name: "uePlaceSwitcherStatePressed"
}, // State
State
{
name: "uePlaceSwitcherStateReleased"
} // State
] // states
Component.onCompleted:
{
state="uePlaceSwitcherStateReleased"
enabled=true
print("Component.onCompleted state: "+state)
}
} // Rectangle
Now, this Rectangle has two states and at the first click Rectangle is not in the neither of two states. Here is debug print after first click:
qml: Component.onCompleted state: uePlaceSwitcherStateReleased
qml: onClicked state:
As you can see, state at onCompleted is ok, but when I first click Rectangle, the state gets emtpy string. Why?!
I think you're changing the state for the MouseArea, not the Rectangle.
According to the documentation,
Every Item based component has a state property and a default state.
The default state is the empty string ("") and contains all of an
item's initial property values.
Without any reference, you're printing the MouseArea state in this line:
print("onClicked state: "+state)
So you should identify the Rectangle state using its id. In your case: uePlaceSwitcher.state.
I've tested the following code and it works fine.
MouseArea
{
anchors.fill: parent
onClicked:
{
print("onClicked state: " + uePlaceSwitcher.state)
if(uePlaceSwitcher.state==="uePlaceSwitcherStateReleased")
{
uePlaceSwitcher.state="uePlaceSwitcherStatePressed"
uePlaceSwitcherPressedAnimation.running=true
ueSignalPlaceSwitcherPressed()
}
else
{
uePlaceSwitcher.state="uePlaceSwitcherStateReleased"
uePlaceSwitcherReleasedAnimation.running=true
ueSignalPlaceSwitcherReleased()
} // if
} // onClicked
} // MouseArea
states:
[
State
{
name: "uePlaceSwitcherStatePressed"
}, // State
State
{
name: "uePlaceSwitcherStateReleased"
} // State
] // states
Component.onCompleted:
{
state="uePlaceSwitcherStateReleased"
enabled=true
print("Component.onCompleted state: "+state)
}
Although in my opinion, we should also use the id in Component.onCompleted because it makes the code easier to follow. It isn't necessary, though.
Component.onCompleted:
{
uePlaceSwitcher.state="uePlaceSwitcherStateReleased"
enabled=true
print("Component.onCompleted state: " + uePlaceSwitcher.state)
}

Custom Button with conditional image and conditional text

I have the following custom QML Button:
import QtQuick.Controls 1.4
import QtQuick 2.5
import QtQuick.Layouts 1.2
import QtMultimedia 5.5
Rectangle {
id: ueButton
property string ueText: ""
property string ueIconPath: ""
width: 256
height: 128
signal ueSignalButtonClicked
gradient: Gradient {
GradientStop {
position: 0
color: "#ffffff"
SequentialAnimation on color {
id: ueButtonClickAnimation
loops: 1
running: false
ColorAnimation {
from: "#ffffff"
to: "#000000"
duration: 25
} // ColourAnimation
ColorAnimation {
from: "#000000"
to: "#ffffff"
duration: 25
} // ColorAnimation
} // SequentialAnimation
} // GradientStop
GradientStop {
position: 0.418
color: "#000000"
} // GradientStop
} // Gradient
border.color: "steelblue"
border.width: 1
radius: 4
antialiasing: true
smooth: true
ColumnLayout {
anchors.fill: parent
antialiasing: true
Image {
Layout.fillWidth: true
Layout.fillHeight: true
Layout.alignment: Qt.AlignHCenter|Qt.AlignTop
Layout.margins: 8
asynchronous: true
horizontalAlignment: Image.AlignHCenter
verticalAlignment: Image.AlignVCenter
fillMode: Image.PreserveAspectFit
smooth: true
source: ueIconPath
} // Image
Text {
text: ueText
Layout.fillWidth: true
Layout.fillHeight: true
Layout.alignment: Qt.AlignHCenter|Qt.AlignVCenter
Layout.topMargin: 8
Layout.leftMargin: 8
Layout.rightMargin: 8
Layout.bottomMargin: 16
color: "#ffffff"
font.bold: true
verticalAlignment: Text.AlignVCenter
horizontalAlignment: Text.AlignHCenter
font.pointSize: 16
textFormat: Text.RichText
} // Text
} // ColumnLayout
MouseArea {
id: ueButtonMouseArea
antialiasing: true
anchors.fill: parent
onClicked: {
ueButtonClickAnimation.running=true
ueSignalButtonClicked()
}
} // MouseArea
} // ueButton
This works fine, but what I want to do now is to solve the following two specular issues:
If urtext is empty the corresponding text is ignored and whole ColumnLayout place is reserved for Image
If ueIconPath is empty, the corresponding image is ingnored and the whole ColumnLayout is reserved for Text
How can I achieve that?
As #BaCaRoZzo already suggested, using styles is preferable solution in this case since the item itself is still Button and so you can use all its properties and signals, including text property to pass your ueText text.
As for hiding elements inside, you can use visible property as suggested below:
UeButton.qml
Button {
id: ueButton
style: ButtonStyle {
background: Rectangle {
color: control.pressed ? "#CCC" : "#DEDEDE"
border.width: 1
border.color: "#999"
radius: 3
}
label: ColumnLayout {
id: layout
spacing: 10
Image {
Layout.alignment: Qt.AlignHCenter
source: control.iconSource
visible: control.iconSource !== ""
}
Text {
text: control.text
visible: control.text !== ""
}
}
}
}
Now using of this component is similar to regular Button:
UeButton {
anchors.centerIn: parent
text: "Some text"
iconSource: "data:image/gif;base64,R0lGODlhEAAQAMQAAORHHOVSKudfOulrSOp3WOyDZu6QdvCchPGolfO0o/XBs/fNwfjZ0frl3/zy7////wAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAACH5BAkAABAALAAAAAAQABAAAAVVICSOZGlCQAosJ6mu7fiyZeKqNKToQGDsM8hBADgUXoGAiqhSvp5QAnQKGIgUhwFUYLCVDFCrKUE1lBavAViFIDlTImbKC5Gm2hB0SlBCBMQiB0UjIQA7"
}
Commenting out text or iconSource will change the button view

How to fill a QTableview using QML Tool Button

I need to press my create button under red circle and by pressing this button i am trying to fill first row of my table view. I am a new user in QT Quick please help me. I have wasted lot of time but have no way to do it.
I am providing UI and code as well please have a look.
Thank you !
import QtQuick 2.2
import QtQuick.Controls 1.2
import QtQuick.Layouts 1.0
import QtQuick.Dialogs 1.0
import "content"
import "images"
ApplicationWindow {
visible: true
title: "Mask Editor: Subsystem"
width: 720
height: 420
minimumHeight: 400
minimumWidth: 720
statusBar: StatusBar {
id: minstatusbar
RowLayout {
id:row1
spacing: 2
width: parent.width
Button {
text:"Unmask"
}
Item { Layout.fillWidth: true }
Button {
text:"OK"
}
Button {
text:"Cancel"
}
Button {
text:"Help"
}
Button {
text:"Apply"
}
}
}
/* ListModel {
id: largeModel
Component.onCompleted: {
for (var i=0 ; i< 10 ; ++i)
largeModel.append({"index":i , "prompt": "pmpt", "variable":i+10, "type" : "Female","tabname":"something"})
}
}*/
Action {
id: openAction
text: "&Open"
shortcut: "Ctrl+O"
iconSource: "images/document-open.png"
onTriggered: fileDialog.open()
tooltip: "Open an Image"
}
TabView {
id:frame
enabled: enabledCheck.checked
tabPosition: controlPage.item ? controlPage.item.tabPosition : Qt.TopEdge
anchors.fill: parent
anchors.margins: Qt.platform.os === "osx" ? 12 : 2
Tab {
id: controlPage
title: "Parameters"
Item {
id:root
anchors.fill: parent
anchors.margins: 8
ColumnLayout {
id: mainLayout
anchors.fill: parent
spacing: 4
GroupBox {
id: gridBox
title: "Grid layout"
Layout.fillWidth: true
ListModel {
id: nestedModel
ListElement{index:"1";prompt:"pmt";variable:10; type: "to be defined";tabname:"something"}
}
GridLayout {
id: gridLayout
anchors.fill: parent
rows: 3
flow: GridLayout.TopToBottom
ToolButton { iconSource: "images/window-new.png"
action:filldata
Accessible.name: "New window"
onClicked: {
nestedmodel.append({"index":i , "prompt": "pmpt", "variable":i+10, "type" : "Female","tabname":"something"})
}
tooltip: "Toggle visibility of the second window" }
ToolButton { iconSource: "images/view-refresh.png"
onClicked: window1.visible = !window1.visible
Accessible.name: "New window"
tooltip: "Toggle visibility of the second window" }
ToolButton { Accessible.name: "Save as"
iconSource: "images/document-save-as#2x.png"
tooltip: "(Pretend to) Save as..." }
TableView{
model: modelcontl
Layout.rowSpan: 3
Layout.fillHeight: true
Layout.fillWidth: true
//anchors.fill: parent
TableViewColumn {
role: "index"
title: "#"
width: 36
resizable: false
movable: false
}
TableViewColumn {
role: "prompt"
title: "Prompt"
width: 120
}
TableViewColumn {
role: "variable"
title: "Variable"
width: 120
}
TableViewColumn {
role: "type"
title: "Type"
width: 200
visible: true
}
TableViewColumn {
role: "tabname"
title: "Tab Name"
Layout.fillWidth: true
visible: true
}
}
}
}
Rectangle{
Layout.fillHeight: true
Layout.fillWidth: true
GridLayout {
//id: gridLayout
rows: 1
flow: GridLayout.TopToBottom
anchors.fill: parent
GridLayout{
id: grid1
columns: 2
anchors.fill: parent
GroupBox {
//id: gridBox
title: "Grid layout"
Layout.fillHeight: true
Layout.fillWidth: true
}
GroupBox {
//id: gridBox
title: "Grid layout"
Layout.fillHeight: true
Layout.fillWidth: true
}
}
}
}
}
}
}
Tab {
title: "Documentation"
Controls { }
}
Tab {
title: "dialog"
MessageDialogs { }
}
}
}
If you want to add a QML control into a cell you just have to define custom delegate. Since you need different delegates for different columns it can be done in a bit "tricky" way with Loader. See my example below:
Component {
id: comboDelegate
ComboBox {
model: ListModel {
ListElement { text: "Banana" }
ListElement { text: "Apple" }
ListElement { text: "Coconut" }
}
}
}
Component {
id: textDelegate
Text {
text: itemText
}
}
TableView {
Layout.fillWidth: true
Layout.fillHeight: true
TableViewColumn{ role: "col1" ; title: "Column1" }
TableViewColumn{ role: "col2" ; title: "Column2" }
TableViewColumn{ role: "col3" ; title: "Column3" }
model: ListModel {
id: myModel
}
itemDelegate: Item {
height: 25
Loader {
property string itemText: styleData.value
sourceComponent: styleData.column === 0 ? comboDelegate : textDelegate
}
}
}
Try this:
TableView {
TableViewColumn{ role: "col1" ; title: "Column1" }
TableViewColumn{ role: "col2" ; title: "Column2" }
TableViewColumn{ role: "col3" ; title: "Column3" }
model: ListModel {
id: myModel
}
}
Button {
text: "Add row"
onClicked: {
myModel.append({col1: "some value",
col2: "Another value",
col3 : "One more value" });
}
}