QML TreeView的樣式和使用時的一些小細節

2021-08-21 22:24:53 字數 1935 閱讀 1387

treeview目前只在 controls 1.4中有,所以在使用的時候要先導入。

關於treeview的item和model,這個在網上搜能搜到很多,同時這個在qt creator的歡迎介面裡輸入treeview,選擇第乙個專案,之後進入專案說明往下拉就能看到。

在使用的時候,treeitem的具體封裝還需要根據你自己的實際使用情況做調整。

model的話底下的這幾個函式必須實現

root.currentitemindex(styledata.index) //發出訊號,這個訊號自己定義

rowdelegate:rectangle{

id: rowdel

color: styledata.selected ? "#595f69" : root.color;

height: 28

tableviewcolumn { //新增一列

title: "default"

role: "text"  //這個role的名字要跟你在model中定義的列的名字一模一樣

width: root.width

resizable: false

headervisible:false

horizontalscrollbarpolicy: qt.scrollbaralwaysoff

onclicked: {

root.currentchildindex(viewtree.currentindex)

ondoubleclicked: {

root.currentchildindex(viewtree.currentindex)

關於上面的 在qml中新增一列的時候 role的命名注意情況:

qhashtestmodel::rolenames() const

qhashnames(qabstractitemmodel::rolenames());

names[1] = "text"; //要跟qml中tableviewcolumn的role一模一樣

return names;

如果上面的role沒有對應的話,那麼下面的這個data函式將進不去;

通常下面的這個case會使用列舉,可讀性更強,這邊只是舉個例子。

qvariant testmodel::data(const qmodelindex &index, int role) const

if (!index.isvalid())

return qvariant();

switch (role)

case 1:

return static_cast(index.internalpointer())->data(0);

樣式和主題

這裡來回顧一下樣式和主題 針對應用中所有activity或者針對某個activity設定樣式,可以通過編輯androidmanifest.xml來完成。1.設定應用中所有activity活動的主題 2.設定某個指定的activity主題 另外,android提供了許多自帶的主題樣式。例如theme....

jquery的屬性和樣式

1.attr 和prop attr 設定或返回被選元素的屬性值 attr 屬性名 獲取屬性 attr 屬性名,屬性值 設定屬性 span attr data id 1002 data id 1001 console.log span attr id 獲取id console.log span att...

jQuery的屬性和樣式

prop 獲取在匹配的元素集中的第乙個元素的屬性值。attr 屬性名 屬性值 設定屬性 全選全部選 change function 反選 change function 2 change function body form action span id span data id 1001 姓名 s...