在我的项目中,我设法使用组件填充网格布局中的一些按钮。但是我无法在按钮中添加样式组件。这是我的代码:
Component {
id: itemgroup
Button { }
}
function addButton () {
for(var i = 0 ; i < 10 ; i++) {
var button = itemgroup.createObject (gridX, {
"id": "btnitemgroup",
"style": buttonstyle,
"text" :"hai"
});
}
}
答案 0 :(得分:0)
import QtQuick 2.6
import QtQuick.Window 2.2
import QtQuick.Controls 1.3
import QtQuick.Controls.Styles 1.3
Window {
visible: true
width: 500
height: 500
id:root
Grid
{
id:gridX
}
function addButton (row) {
var styleButton = 'import QtQuick 2.6;import QtQuick.Controls 1.3
import QtQuick.Controls.Styles 1.3; Button { text:"hai"; style: ButtonStyle {
background: Rectangle {
implicitWidth: 100
implicitHeight: 25
border.width: control.activeFocus ? 2 : 1
border.color: "red"
radius: 10
}
}
}'
for(var i = 0 ; i < 10 ; i++) {
Qt.createQmlObject(styleButton, gridX);
}
}
Component.onCompleted:
{
addButton()
}
}