我想添加一個tabButton到TabBar動態按下按鈕,但我花了很多時間搜索,但我沒有得到如何添加,下面是代碼,我我工作的:動態添加TabButton到QML中的TabBar
MyTabButton.qml
import QtQuick 2.4
import QtQuick.Controls 2.2
Item
{
property int BtnWidth:0
property int BtnHeight:0
property string BtnText: ""
property bool isChecked : false
TabButton
{
id:tabBtn
text:BtnText
width:BtnWidth
height:BtnHeight
}
}
MainForm.qml
import QtQuick 2.4
import QtQuick.Controls 2.2
Rectangle
{
Button
{
id:button
width:100
height:100
anchors.top:parent.top
text:qStr("Add")
onClicked{
//How to add logic here to add tab in below tabBar.
}
}
TabBar
{
id:tabBar
anchors.top:button.bottom
width:500
height:500
}
}
這正是我所需要的,但如果我想使用一個函數在** MyTabButton中創建** say ** doSomething()**如何訪問** tabBar中的onCurrentIndexChanged()事件處理函數? – pra7
你想調用所有'TabButtons'的'doSomething'或者只調用'doBometon'嗎? – derM
我需要調用所有'TabButtons'的'doSomething',因爲我正在對TabButton進行一些繪製...... – pra7