qlistview

第15.23节 PyQt(Python+Qt)入门学习:Model/View架构中QListView视图配套Model的开发使用

↘锁芯ラ 提交于 2020-01-25 19:58:54
老猿Python博文目录 专栏:使用PyQt开发图形界面Python应用 老猿Python博客地址 一、概述 QListView理论上可以和所有QAbstractItemModel派生的类如QStringListModel、QDirModel、QFileSystemModel、QStandardItemModel等对接,但QListView实际上能展示的数据仅一列,对于复杂的树形层次使用Model使用QListView来展现意义不大。本节通过几个简单代码案例来阐述QListView/Model开发的过程。 二、QListView/QStringListModel 2.1、QStringListModel介绍 QStringListModel是Qt提供的一个已经实现QAbstractItemModel相关接口的Model,适合于展示一系列字符串的简单视图如QListView对象和QComboBox对象。 QStringListModel提供了所有可编辑模型的标准函数,将字符串列表中的数据存储为一个一列多行的模型。 使用index(int row, int column = 0, QModelIndex parent = QModelIndex())函数获取与项对应的模型索引,使用flags(QModelIndex index)获取项标志;使用data()函数读取项数据

Breadcrumbs navigation using QToolBar and QListView

久未见 提交于 2020-01-15 09:48:27
问题 I have JSON data something like this {"books":{ "web":{ "front-end":{ "html":["the missing manual", "core html5 canvas"], "css":["css pocket reference", "css in depth"], "js":["you don't know js", "eloquent javascript"] }, "back-end":{ "php":["modern php", "php web services"], "python":["dive into python", "python for everybody", "Think Python", "Effective Python", "Fluent Python"] } }, "database":{ "sql":{ "mysql":["mysql in a nutshell", "mysql cookbook"], "postgresql":["postgresql up and

How to sort items in Qt QListview using Qt.UserRole

穿精又带淫゛_ 提交于 2020-01-06 01:51:54
问题 I'm having some problem sorting the items in my QListView using values in a field I specified. Basically what I'm trying to do is this: Detect faces in a collection of photos and display them in a QListView Cluster the faces (images) Update the view by placing items in the list (which are face images) belonging to the same cluster in together. Concretely, if item 1, 3, 5 are in one cluster and items 2, 4, 6 are in another, then items 1, 3, 5 should be displayed (in whatever permutations)

How do I get the items selected from a QListView?

梦想与她 提交于 2019-12-29 08:36:07
问题 { ... nrow = 10; ncol = 1; /*create QListView */ m_listView = new QListView(this); m_listView->setGeometry(QRect(QPoint(0,100), QSize(100, 150))); QStandardItemModel *model = new QStandardItemModel( nrow, 1, this ); //fill model value for( int r=0; r<nrow; r++ ) { QString sstr = "[ " + QString::number(r) + " ]"; QStandardItem *item = new QStandardItem(QString("Idx ") + sstr); model->setItem(r, 0, item); } //set model m_listView->setModel(model); m_listView->setSelectionMode( QAbstractItemView

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

和自甴很熟 提交于 2019-12-27 10:37:14
问题 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

Can I add columns in a QListView in Qt?

浪子不回头ぞ 提交于 2019-12-24 13:08:09
问题 Can I add columns in a QListView object?? here's something I found here: model->setHeaderData( 0, Qt::Horizontal, "numéro" ); model->setHeaderData( 1, Qt::Horizontal, "prénom" ); model->setHeaderData( 2, Qt::Horizontal, "nom" ); //... model->setData( model->index( line, 0 ), contact->num(), Qt::DisplayRole ); model->setData( model->index( line, 1 ), contact->prenom(), Qt::DisplayRole ); model->setData( model->index( line, 2 ), contact->nom(), Qt::DisplayRole ); Since I'm using Qt Creator 2.0

add feature for previous question PySide2 QListView and QTableView

99封情书 提交于 2019-12-24 10:15:12
问题 The previous question was PySide2 QListView QTableView sync problem Imagine to have another dict4 in the data structure: 'dict4':{'k8':'v8', 'EXISTING_DICT':'dict2'}, Meaning, that a dictionary could include another existing dictionary. So the representation in the QTableView shouldn't be directly showed, but: 1) Show just the name of it in the QTableView: k1 | v1 ------- k2 | v2 ------- k3 | v3 ------- dict2 2) If double click it on it: select the existing dictionary in the QListView, which

How to tell where an item was dropped in qlistview?

那年仲夏 提交于 2019-12-24 09:11:09
问题 I have a custom QListView: from PyQt4.QtCore import * from PyQt4.QtGui import * from Diagnostics import Trace2 #writes to log file import traceback class ListOrderView(QListView): itemMoved = pyqtSignal(int, int, QStandardItem) # Old index, new index, item def __init__(self, parent=None): try: super(ListOrderView, self).__init__(parent) self.setAcceptDrops(True) self.setDragEnabled(True) self.setDragDropMode(QAbstractItemView.InternalMove) self.setDefaultDropAction(Qt.MoveAction) self

How to set minimum height of QListWidgetItem?

允我心安 提交于 2019-12-23 07:33:27
问题 How can I set the minimum height of a QListWidgetItem ? I'm using QListWidget::setItemWidget() with a customized widget, and although I explicitly declared minimum height of my customized widget, those QListWidgetItem s still have a pretty low height attribute. 回答1: Use setSizeHint on the items. void QListWidgetItem::setSizeHint ( const QSize & size ) This is the right method for telling the delegate how much screen it must preserve for the item. Look at http://qt-project.org/doc/qt-4.8

Is it possible to add a custom widget into a QListView?

不打扰是莪最后的温柔 提交于 2019-12-23 06:28:07
问题 I have a large log data (100, 1000, 100000, ... records) and I want to visualize it in the following manner: Which widget (e.g. QListView , QListWidget ) should I use and how, in order to stay away from performance and memory problems? 回答1: Is it possible to add a custom widget into a QListView? Please, read about: How to display a scrollable list with a substantial amount of widgets as items in a Qt C++ app? I want to show every log message in the above format Solution To achieve the desired