qlistwidget

How to list all items from QListWidget

此生再无相见时 提交于 2021-01-27 21:00:05
问题 I apology if it has been already asked but would you please clarify it again: how to get all ListWidgetItems listed in QListWidget? Poster later: Here it's in action. There are 5 items in a list. Subtracting one results 4. from PyQt4 import QtGui, QtCore class Dialog_01(QtGui.QMainWindow): def __init__(self): super(QtGui.QMainWindow,self).__init__() myQWidget = QtGui.QWidget() myBoxLayout = QtGui.QVBoxLayout() myQWidget.setLayout(myBoxLayout) self.setCentralWidget(myQWidget) self.lw = QtGui

How to scroll QListWidget to selected item

北城余情 提交于 2021-01-27 13:07:53
问题 The code below creates a single dialog window with QListWidget and QPushButton . Clicking the button fires up a scroll() function which finds and selects an "ITEM-0011". I wonder if there is a way to scroll the list widget so the selected ITEM-0011 is at the top edge of QListWidget ? Here is how the end result should look like: from PyQt4 import QtCore, QtGui app=QtGui.QApplication([]) def scroll(): item = listWidget.findItems('ITEM-0011', QtCore.Qt.MatchRegExp)[0] item.setSelected(True)

Remove all items from QListWidget in a cycle

为君一笑 提交于 2020-07-03 09:09:45
问题 I have the following code, which should remove all items from QListWidget, but it removes only one item on one click (not all). Why? How is it right? I don't want to use clear() method. I want to remove them gradually. def onRemoveItems(self): # button click event for i in range(self.myListWidget2.count()): itemI = self.myListWidget2.item(i) self.myListWidget2.takeItem(self.myListWidget2.row(itemI)) 回答1: The concept is the same as removing items from a list: if you use increasing indexes and

Remove all items from QListWidget in a cycle

▼魔方 西西 提交于 2020-07-03 09:09:26
问题 I have the following code, which should remove all items from QListWidget, but it removes only one item on one click (not all). Why? How is it right? I don't want to use clear() method. I want to remove them gradually. def onRemoveItems(self): # button click event for i in range(self.myListWidget2.count()): itemI = self.myListWidget2.item(i) self.myListWidget2.takeItem(self.myListWidget2.row(itemI)) 回答1: The concept is the same as removing items from a list: if you use increasing indexes and

PySide: QListWIdget item disappearing when I remove and add item sometimes

依然范特西╮ 提交于 2020-05-24 07:29:13
问题 The bounty expires in 2 days . Answers to this question are eligible for a +50 reputation bounty. Shock-o-lot wants to draw more attention to this question. I have a QListWidget with custom widgets. I am seeing an issue where if I do the following: add two items Remove the second item Add another item then the first item's widget contents disappears until I either resize the window, or add a third item. import sys from PySide.QtGui import * from PySide.QtCore import * class StagingWidget

Sorting a QListWidget using sortItems()

前提是你 提交于 2020-05-15 10:04:58
问题 I have issues while using sortItems() on a QListWidget. Here is what happens: Changes this: A z d C E o I to this: A C I d e o z But i want it to be: A C d e I o z Any way to change to make it sort like that? 回答1: QListWidget uses the DisplayRole (the item's text) for sorting and calls QString::localeAwareCompare on them. To override the default, you can either change the locale used (see QLocale) or have your own QListWidgetItem subclass reimplementing QListWidgetItem::operator< and let it

How can i iterate through QListWidget items and work with each item?

百般思念 提交于 2020-05-12 11:06:26
问题 In CSharp its as simple as writting : listBox1.Items.Add("Hello"); listBox1.Items.Add("There"); foreach (string item in listBox1.Items ) { MessageBox.Show(item.ToString()); } and I can easily add different objects to a list box and then retrieve them using foreach. I tried the same approach in Qt 4.8.2 but it seems they are different. Though they look very similar at the first. I found that Qt supports foreach so I went on and tried something like : foreach(QListWidgetItem& item,ui-

Drop one or more files into ListWidget or LineEdit

人走茶凉 提交于 2020-04-16 09:56:18
问题 I've been struggling for a good week trying to figure this out myself, and I haven't found any good PyQt5 examples online, so here I am. I want to be able to do two things: drag and drop one or more files from an external window (Finder on a Mac or Windows Explorer? I'm blanking on what it is called on Windows) into a ListWidget and do the same thing, but drop a single file into a LineEdit. I want the full path of the file to appear, so that I can open it up later (not included in this

Qt中QListWidget取消选择事件

拜拜、爱过 提交于 2020-03-05 15:11:11
1.出现的问题 在使用QListWidget的时候,有这样的业务逻辑。用户切换节点后,需要判断一些条件决定是否真正跳转至下个节点,那么怎么拦截这个事件就是本次文档的主要内容。 2.解决办法 使用eventfilter,在QListWidget的上级控件中,安装事件监听器。 ui->listWidget->viewport()->installEventFilter(this); 注意是listWidget->viewport(),而不是listWidget 在上级控件中继承eventfiler方法拦截事件信息,如下代码 bool XXXXX::eventFilter(QObject* watched, QEvent* event) { if (watched == ui->listWidget->viewport()) { qDebug() << event->type(); if (event->type() == QEvent::MouseButtonPress && m_bIsChanged) { MessageDialog::dialogShow(MessageDialog::Check, tr("Warning"), tr("Please save the current group first")); event->ignore(); return true; } }

PySide: Drag and drop files into QListWidget

一笑奈何 提交于 2020-02-20 10:39:51
问题 This is my first entry here so apologies for any newbie mistakes. I've searched both here and Google with no luck before posting. I want to be able to add images to a QListWidget, using drag and drop from a file browser. Dropping a valid file on the list widget also needs to trigger a function in the main class of my app, and pass it the image path. I found this code that does exactly that, but for PyQt4. Importing QtCore and QtGui from PySide instead of PyQt4 produces a segmentation fault