自定義QTreeView中的條目編輯器

2021-06-16 08:22:57 字數 1020 閱讀 6253

預設情況下qtreeview中的條目在使用者雙擊情況下會產生編輯器,允許使用者輸入,但是自己用了這麼久,每個功能都是不需要的,往往都是右鍵啊,其它功能鍵啊,啟用編輯器。

而同時,在專案中,這種原生的編輯器往往都不能滿足需求,因為在某些機器測試情況下,會出現怪怪的樣子,不是編輯器的高度過窄,就是不能限制使用者輸入,而這是非常重要的。今天,我們用qitemdelegate生成自己的編輯器(當然編輯器是qlineedit)。

editdelegate::editdelegate(qobject* parent)

:qitemdelegate(parent)

qwidget* editdelegate::createeditor(qwidget* parent,

const qstyleoptionviewitem& option,

const qmodelindex& index) const

return editor;

}void editdelegate::seteditordata(qwidget* editor,const qmodelindex& index) const

}void editdelegate::setmodeldata(qwidget* editor,

qabstractitemmodel* model,

const qmodelindex& index

) const

}void editdelegate::updateeditorgeometry(qwidget* editor,

const qstyleoptionviewitem& option,

const qmodelindex& index

) const

二話不說,貼**(主要來自qt高階程式設計一書,感謝作者)

使用的話,當使用qtreeview槽函式edit(位置索引)時,就跳出這個編輯器了,而且還可以通過樣式表設定外觀,挺不錯的。

自定義 ProgressBar 進度條 自定義樣式

今天學習給progressbar換個樣式,先看效果圖 c h,e d8 z f j x 原理 在xml檔案中分別定義進度條背景 第一進度顏色 第二進度顏色,然後在progressbar的android progressdrawable屬性應用即可。6 j a7 c h b k h q y g s d...

自定義進度條

自定義進度條 1 繪製底色 灰色 2 繪製進度 藍色 3 繪製最大的進度 純藍色 rectf rf new rectf 0,0,mwidth,mheight 繪製圓角矩形,背景色為畫筆顏色 mpaint.setcolor color.rgb 220,220,220 canvas.drawroundr...

自定義滾動條

滾動條從外觀來看是由兩部分組成 1.滑塊 可以滑動的部分 2.軌道 即滑塊的軌道,一般來說滑塊的顏色比軌道的顏色深。滾動條的css樣式主要有三部分組成 1 webkit scrollbar 定義了滾動條整體的樣式 可以改變滾動條的寬度 2 webkit scrollbar thumb 滑塊部分 可以...