qlistwidget

PyQt4: How do you iterate all items in a QListWidget

淺唱寂寞╮ 提交于 2019-12-04 15:43:09
问题 Currently, I use the following while loop in a class that inherits QtGui.QListWidget to iterate all items: i = 0 while i < self.count(): item = self.item(i) i += 1 I was hoping I could use: for item in self.items(): but the items() method wants a QMimeData object which I don't know how to construct to return all items. Is there a cleaner approach than my while loop above? 回答1: I don't know what's it with the MIME type either, and I couldn't find a convenience method either. But you could

Detecting if an item is clicked at at some row in a QlistWidget

醉酒当歌 提交于 2019-12-04 04:45:29
问题 I Have been given this simple task , I have this list where i instert items whenever ok is clicked,void Form::ok() handle that event is supposed to add new list items to the list. Now what am not able to do is to detect the if an item is clicked at at some row then do something according to that, this is my code.. #include "form1.h" #include "form.h" #include "ui_form.h" #include "ui_form1.h" #include<QScrollArea> #include<QScrollBar> //#include <QgeoPositioninfo.h> Form::Form(QWidget *parent

Multiple Selection QTreeWidget

佐手、 提交于 2019-12-04 01:05:56
Does anyone know if its possible to select multiple items on a QTreeWidget and how to go about enabling the multiple selection? All the items I want to be selectable are top level QTreeWidgetItems and all their children are set to be disabled (i.e QTreeWidgetItem.setDisabled(True) ) Mike Ramirez It is, you'll want to call setSelectionMode during init to enable QAbstractItemView::MultiSelection. QTreeView/QTreeWidget inherit QAbstractItemView, so it is available. Then to disable the items, just hook on to QTreeWidgets.itemSelectionChanged() signal. I think below will help: youQTreeWidget

Remove selected items from listWidget

微笑、不失礼 提交于 2019-12-03 22:30:16
How to remove selected items from qlistWidget . I have tried write the following code, but does not work. QList<QListWidgetItem*> items = ui->listWidget->selectedItems(); foreach(QListWidgetItem item, items){ ui->listWidget->removeItemWidget(item); } Now, how to remove the items that I selected from the qlistWidget ? One way to remove item from QListWidget is to use QListWidget::takeItem which removes and returns the item : QList<QListWidgetItem*> items = ui->listWidget->selectedItems(); foreach(QListWidgetItem * item, items) { delete ui->listWidget->takeItem(ui->listWidget->row(item)); }

Qt ListWidget item 发起拖放

帅比萌擦擦* 提交于 2019-12-03 20:21:29
第一步:重写类 MyListWidget 继承自 QListWidget 第二步:重写 mousePressEvent 函数 和 mouseMoveEvent 函数 void mousePressEvent(QMouseEvent* event); void mouseMoveEvent(QMouseEvent* event); MyListWidget.h 文件 #ifndef MYLISTWIDGET_H #define MYLISTWIDGET_H #include <QListWidget> // 包含所有用到的界面类 #include <QtGui> class MyListWidget : public QListWidget { Q_OBJECT public: MyListWidget(QWidget *parent); ~MyListWidget(); private: // 拖放起点 QPoint m_startPos; // 被拖放的item QListWidgetItem* m_sitem; void mousePressEvent(QMouseEvent* event); void mouseMoveEvent(QMouseEvent* event); }; #endif // MYLISTWIDGET_H MyListWidget.cpp 文件

PyQt4: How do you iterate all items in a QListWidget

China☆狼群 提交于 2019-12-03 09:46:35
Currently, I use the following while loop in a class that inherits QtGui.QListWidget to iterate all items: i = 0 while i < self.count(): item = self.item(i) i += 1 I was hoping I could use: for item in self.items(): but the items() method wants a QMimeData object which I don't know how to construct to return all items. Is there a cleaner approach than my while loop above? I don't know what's it with the MIME type either, and I couldn't find a convenience method either. But you could write a simple method like this and be done: def iterAllItems(self): for i in range(self.count()): yield self

QListWidget项视图类之

匿名 (未验证) 提交于 2019-12-03 00:21:02
1 ) QListWidget::QListWidget ( QWidget *parent = 0 ) // 构造一个父对象为parent的ListWidget。 2 ) void QListWidget::addItem ( const QString & label ) // 添加一个新的项目,在新添加的项目中添加label标签。 3 ) void QListWidget::addItem ( QListWidgetItem *item ) // 添加项目item。 4 ) void QListWidget::addItems ( const QStringList & labels ) // 添加一列项目。 5 ) void QListWidget::clear () 〔slot〕 // 清除该ListWidget中的所有项目。 6 ) QListWidgetItem *QListWidget::currentItem () const //返回当前活动项目。 7 ) void QListWidget::editItem ( QListWidgetItem *item ) //如果项目item是可编辑的,开始编辑项目item。 8 ) QList<QListWidgetItem *> QListWidget::findItems( constQString & text,

the slot don't work for QListWidget itemClicked (pyqt)

纵然是瞬间 提交于 2019-12-02 21:04:52
问题 I create a QListWidget, and I want to connect the itemClicked with my slot. And the following code is OK: when I click the item, the listwidgetclicked has been called from PyQt5.QtWidgets import * from PyQt5.QtCore import * import sys class MainWindow(QMainWindow): def __init__(self, parent=None): super(MainWindow, self).__init__(parent) self.imagelabel = QLabel() layout = QVBoxLayout() self.imagelabel.setLayout(layout) self.setCentralWidget(self.imagelabel) label1 = QLabel('hello, world')

Qt QListWidget

半世苍凉 提交于 2019-12-02 18:54:56
以下代码是 List Widget 添加数据项的代码,一般放在构造函数即可。 /*********************添加数据项*********************/ QIcon icon1("C:\\Users\\Administrator.USER-20190313RI\\Desktop\\img\\book.png"); QListWidgetItem* item = new QListWidgetItem(icon1, "book"); // 设置关联数据 item->setData(Qt::UserRole, 1); item->setData(Qt::ToolTipRole, "this is tooltip!"); ui.listWidget->addItem(item); QIcon icon2("C:\\Users\\Administrator.USER-20190313RI\\Desktop\\img\\heart.png"); ui.listWidget->addItem(new QListWidgetItem(icon2, "heart")); QIcon icon3("C:\\Users\\Administrator.USER-20190313RI\\Desktop\\img\\location.png"); ui.listWidget-

QListWidget, insert linebreak for longer text

拥有回忆 提交于 2019-12-02 05:55:05
问题 I want to use QListWidget to display my content. But some of the content is quite long and I want to make the text continue on a second row instead of showing a horizontal scrollbar. I use Qt Creator and I can't seem to find any options in the design view. 回答1: Enable word wrapping by calling void setWordWrap ( bool on ) and set text elide mode to Qt::ElideNone void setTextElideMode ( Qt::TextElideMode mode ) Also you may check that you didn't set too small maximum height for your items in