मेरे पास QSplitter के अंदर QListView और QTabWidget है। QListView कस्टम मॉडल और कस्टम प्रतिनिधियों का उपयोग कर रहा है। प्रतिनिधि में मैंने रंग और आकार संकेत विधियों को फिर से लागू किया। लेकिन जब मैं दृश्य का आकार बदलता हूं - तत्वों की ऊंचाई का पुनर्मूल्यांकन नहीं किया जाता है। मेरे द्वारा यह कैसे किया जा सकता है? नमूना छवियों:QAbstractItemView को कैसे लागू करें आइटम आकार का पुनर्मूल्यांकन करें संकेत
गूगल में मैंने पाया कि यह emit layoutChanged मॉडल से करने के लिए संभव है, लेकिन मैं केवल वर्तमान दृश्य अद्यतन किया जा करना चाहते हैं, क्योंकि मॉडल की सामग्री को बदल नहीं करता है।
प्रतिनिधि कोड:
void ChatItemDelegate::paint(QPainter *painter, const QStyleOptionViewItem& option, const QModelIndex& index) const
{
painter->save();
ChatItem *item = static_cast< ChatItem * >(index.internalPointer());
QTextDocument doc;
doc.setHtml(item->htmlText());
doc.setTextWidth(option.rect.width());
QRect clip(0, 0, option.rect.width(), option.rect.height());
painter->translate(option.rect.topLeft());
QColor bgColor = index.row() % 2 ? QColor(255, 0, 0, 40) : QColor(0, 255, 0, 40);
painter->fillRect(clip, bgColor);
doc.drawContents(painter, clip);
qDebug() << "paint: " << option.rect.width() << " idx: " << index.row();
painter->restore();
}
QSize ChatItemDelegate::sizeHint(const QStyleOptionViewItem& option, const QModelIndex& index) const
{
ChatItem *item = static_cast< ChatItem * >(index.internalPointer());
QTextDocument doc;
doc.setHtml(item->htmlText());
doc.setTextWidth(option.rect.width());
qDebug() << "hint: " << option.rect.width() << " idx: " << index.row();
return doc.size().toSize();
}
मदद नहीं करता है। वर्तमान में मैं क्यूएसप्लिटर के स्प्लिटर से जुड़े सिग्नल से जुड़ा हुआ हूं और प्रत्येक आकार पर कॉल व्यू-> मॉडल() -> रीसेट() को कॉल करता हूं। मुझे नहीं लगता कि यह अच्छा है, मैं अब बहुत सारी वस्तुओं के लिए इसका परीक्षण करने की कोशिश करूंगा। –
देखें-> मॉडल() -> रीसेट() मेगा धीमा है :( –
QAbstractItemView :: updateGeometries()? – Chris