我目前正在通過樣式表定義 QTreeView 中專案的高度
QTreeView {
background: palette(window);
color: palette(text);
border: none;
}
QTreeView::item {
height: 40px;
padding-top: 0.5ex;
padding-bottom: 0.5ex;
margin: 2px;
}
這樣,樹中的所有專案都將具有相同的高度。是否可以為孩子定義不同的高度?
uj5u.com熱心網友回復:
我不確定這是否可以通過樣式表完成。實作這一點的正常方法是覆寫QAbstractItemModel::data并讓它回傳與Qt::SizeHintRole資料角色關聯的特定值。
QVariant new_model::data (const QModelIndex &index, int role) const
{
if (role == Qt::SizeHintRole) {
/*
* Calculate required size hint based on model data etc.
*/
QSize size = ...;
return size;
}
/*
* Defer to base class implementation.
*/
return base_class::data(index, role);
}
轉載請註明出處,本文鏈接:https://www.uj5u.com/shujuku/448164.html
