qlistview

How to force QAbstractItemView recalculate items sizeHints

☆樱花仙子☆ 提交于 2019-11-28 01:56:23
I have QListView and QTabWidget inside QSplitter. QListView is using custom model and custom delegates. In delegate I reimplemented paint and sizeHint methods. But when I resize view - height of elements doesn't recalculated. How can I fix it? Sample images: In google I found that it is possible to emit layoutChanged from the model, but I want only current view to be updated, because content of model doesn't change. Delegate code: void ChatItemDelegate::paint( QPainter *painter, const QStyleOptionViewItem& option, const QModelIndex& index ) const { painter->save(); ChatItem *item = static_cast

How to get QString from QListView selected item in Qt?

偶尔善良 提交于 2019-11-27 14:40:58
问题 I need to get the selected item name in QListView as a QString . I have tried to google, but I haven't found anything useful. 回答1: It depends on selectionMode lets say you have ExtendedSelection which means you can select any number of items (including 0). ui->listView->setSelectionMode(QAbstractItemView::ExtendedSelection); you should iterate through ui->listView->selectionModel()->selectedIndexes() to find indexes of selected items, and then call text() method to get item texts: QStringList

How to force QAbstractItemView recalculate items sizeHints

a 夏天 提交于 2019-11-26 22:03:16
问题 I have QListView and QTabWidget inside QSplitter. QListView is using custom model and custom delegates. In delegate I reimplemented paint and sizeHint methods. But when I resize view - height of elements doesn't recalculated. How can I fix it? Sample images: In google I found that it is possible to emit layoutChanged from the model, but I want only current view to be updated, because content of model doesn't change. Delegate code: void ChatItemDelegate::paint( QPainter *painter, const

QListView/QListWidget with custom items and custom item widgets

僤鯓⒐⒋嵵緔 提交于 2019-11-26 21:51:28
I'm writing a PyQt application and am having some trouble creating a custom list view. I'd like the list to contain arbitrary widgets (one custom widget in particular). How would I go about this? It seems that the alternative would be to create a table or grid view wrapped in a scrollbar. However, I'd like to be able to take advantage of the model/view approach as well as the nesting (tree-view) support the built-ins handle. To clarify, the custom widgets are interactive (contain buttons), so the solution requires more than painting a widget. Idan K I think you need to subclass QItemDelegate .

How to make item view render rich (html) text in Qt

眉间皱痕 提交于 2019-11-26 11:44:52
Suppose my model has items with the following string for Qt::DisplayRole <span>blah-blah <b>some text</b> other blah</span> I want QTreeView (actually, any item view) to render it like a rich text. Instead, item views render it like a pure text by default. How to achieve the desired rendering? Actually, this is a search results model. User enters a text, some document is searched against that text and the user is presented with search results, where the words being searched should be bolder than surrounding text. serge_gubenko I guess you can use setItemDelegate method of the treeview to setup

QListView/QListWidget with custom items and custom item widgets

ぃ、小莉子 提交于 2019-11-26 08:04:47
问题 I\'m writing a PyQt application and am having some trouble creating a custom list view. I\'d like the list to contain arbitrary widgets (one custom widget in particular). How would I go about this? It seems that the alternative would be to create a table or grid view wrapped in a scrollbar. However, I\'d like to be able to take advantage of the model/view approach as well as the nesting (tree-view) support the built-ins handle. To clarify, the custom widgets are interactive (contain buttons),