PyQT: Get contents CustFormWidgetIem inside QListWidgetItem

PyQT: Get contents CustFormWidgetIem inside QListWidgetItem

By : user2172977
Date : October 22 2020, 08:10 AM
fixed the issue. Will look into that further The currentItemChanged signal sends the current and the previous currentItem so we can use the first data directly. On the other hand, as the OP points out, its code is based on a previous answer from me in which it states that in these cases it is better to save the data in the QListWidget since it has an internal model, so in this case we can take advantage of this to obtain the data:
code :
class ParentWid(QtWidgets.QDialog, Ui_ParentWidget):
    def __init__(self, data={}, parent=None):
        super(ParentWid, self).__init__(parent)
        self.data = data

    @QtCore.pyqtSlot("QListWidgetItem *", "QListWidgetItem *")
    def print_info(self, current, previous):
        v = (("id", Roles.IdRole), ("name", Roles.NameRole), ("version", Roles.VersionRole), ("installed", Roles.InstalledRole),)
        for k, r in v:
            print(k,  current.data(r))

    def set_widget_data(self):
        for item in self.data:
            lst_item = QtWidgets.QListWidgetItem()
            custFormItem = CustomFormWidget(item, lst_item)

Share : facebook icon twitter icon
How can I get the height of a QListWidgetItem in a QListWidget in PyQt?

How can I get the height of a QListWidgetItem in a QListWidget in PyQt?

By : user3700398
Date : March 29 2020, 07:55 AM
like below fixes the issue In general, it's not possible to guarantee the exact sizes of widgets, because there are so many different factors that come in to play. Widgets will rendered differently depending on the window manager in use, the current GUI style, the fonts, etc - and each platform has it's own peculiarities.
To get a better understanding of all this, I would suggest you take a look at Qt's own overviews of window geometry, widgets and layouts and layout management.
How to do that when the mouse pointer hovor QListWidgetItem, then the QListWidgetItem emit a signal?

How to do that when the mouse pointer hovor QListWidgetItem, then the QListWidgetItem emit a signal?

By : user7041947
Date : March 29 2020, 07:55 AM
it should still fix some issue override mouseMoveEvent and grab the QListWidgetItem under the cursor with itemAt(event.pos())
edit: instead of overriding mouseEvent you can use the signal entered which will also pass the ModelIndex of the item end then use leaveEvent to clear the stacked widget, you need to activate mouseTracking for this to work
Can I override the inputs to the __lt__ comparator of a QListWidgetItem? (PyQt)

Can I override the inputs to the __lt__ comparator of a QListWidgetItem? (PyQt)

By : 东营火车站酒店小姐
Date : March 29 2020, 07:55 AM
I wish did fix the issue. QListWidget is one of the "convenience" classes (like QTreeWidget and QTableWidget). Using them is fine as long as your requirements are quite simple. But as soon as you want something a little more sophisticated, the inflexibility soon begins to show.
You can solve your problems fairly easily by switching to the more generic QListView class with a a QStandardItemModel. This requires a little more work to set up, but it will immediately bring a lot more flexibility.
code :
from PyQt4 import QtGui

class ProductListItem(QtGui.QStandardItem):
    def __lt__(self, other):
        listview = self.model().parent()
        this_widget = listview.indexWidget(self.index())
        other_widget = listview.indexWidget(other.index())
        return this_widget.getText() < other_widget.getText()

class ProductItemWidget(QtGui.QWidget):
    def __init__(self, product_name, parent=None):
        super(ProductItemWidget, self).__init__(parent)
        self.label = QtGui.QLabel(product_name, self)
        layout = QtGui.QVBoxLayout(self)
        layout.setContentsMargins(0, 0, 0, 0)

    def getText(self):
        return self.label.text()

class Window(QtGui.QWidget):
    def __init__(self):
        self.list = QtGui.QListView(self)
        layout = QtGui.QHBoxLayout(self)
        # model must have the listview as parent
        model = QtGui.QStandardItemModel(self.list)
        for key in 'MHFCLNIBJDAEGK':
            item = ProductListItem()
            widget = ProductItemWidget('Item %s' % key, self.list)
            self.list.setIndexWidget(item.index(), widget)

if __name__ == '__main__':

    import sys
    app = QtGui.QApplication(sys.argv)
    window = Window()
    window.setGeometry(500, 300, 150, 300)
How to style (rich text) in QListWidgetItem and QCombobox items? (PyQt/PySide)

How to style (rich text) in QListWidgetItem and QCombobox items? (PyQt/PySide)

By : Jesus Manriquez
Date : March 29 2020, 07:55 AM
will be helpful for those in need You could use html/css-likes styles, i.e just wrap your text inside tags:
code :
item.setData( QtCore.Qt.UserRole, "<b>{0}</b>".format('data to store for this QListWidgetItem'))
item.setData(0, QFont("myFontFamily",italic=True), Qt.FontRole)
# use addItem or insertItem (both works)
# the number ("0" in this case referss to the item index)
#set at tooltip
combo.setItemData(0,"a tooltip",Qt.ToolTipRole)
# set the Font Color
#set the font
combo.setItemData(0, QtGui.QFont('Verdana', bold=True), Qt.FontRole)
How to undo an edit of a QListWidgetItem in PySide/PyQt?

How to undo an edit of a QListWidgetItem in PySide/PyQt?

By : jgreen
Date : March 29 2020, 07:55 AM
fixed the issue. Will look into that further That tutorial you mentioned is really not very helpful. There are indeed many approaches to undo-redo implementation for views, we just need to choose the simplest one. If you deal with small lists, the simpliest way is to save all data on each change and restore full list from scratch on each undo or redo operation.
If you still want atomic changes list, you can track user-made edits with QListWidget::itemChanged signal. There are two problems with that:
code :
def __init__(self):
    self.textBeforeEdit = ""

def itemChanged(self, item):
    command = CommandEdit(self.todoList, item, self.todoList.row(item),
        "Rename item '{0}' to '{1}'".format(self.textBeforeEdit, item.text()))

def currentItemChanged(self, item):
    self.textBeforeEdit = item.text()
class CommandEdit(QtGui.QUndoCommand):
    def __init__(self, listWidget, item, row, textBeforeEdit, description):
        super(CommandEdit, self).__init__(description)
        self.listWidget = listWidget
        self.textBeforeEdit = textBeforeEdit
        self.textAfterEdit = item.text()
        self.row = row

    def redo(self):

    def undo(self):
Related Posts Related Posts :
  • Submitting login form with scrapy
  • How do i edit the favicon in the Browsable API in Django REST framework?
  • multiprocessing.Pool.map_async doesn't seem to... do anything at all?
  • Python Selenium: Stale Element Reference Exception Error
  • Datetime conversion - How to extract the inferred format?
  • Import YAML variables automatically?
  • How to create a powershell shortcut for my python file
  • Python's 'set' operator doesn't work with numpy.nan
  • Pass object fields and one2many fields on same method - Odoo v8
  • Select columns based on column name and location in Pandas
  • Standardizing timeseries in Pandas using interpolation
  • How many tweets can be collected?
  • how format specifier taking value while tuple list is passed
  • How to print a numpy array with data type?
  • Timeout child thread for python3
  • How can I regroup a dataframe and accumulate a colume's values?
  • Bulk Insert into SQL Server with Python not working
  • Removing last rows of each group based on condition in a pandas dataframe
  • Why the css file can not be found in Django template?
  • targeting center of mass - scipy / numpy
  • Foursquare - get tips from VENUE_ID
  • Unpack a dictionary to format
  • encoding special characters in python2
  • Replacing integers with NaN results in the entire column becoming float dtype
  • Python 3.6 - BeautifulSoup4, parse table AttributeError: ResultSet object has no attribute 'findAll'
  • Convert panda date list to python list of date strings
  • escape response from Scrapy to parse json
  • How to create a same dropdown menu for different labels?
  • Why are some python variables uppercase whereas others are lowercase?
  • Machine Learning, What are the common techniques for feature engineering and presenting the model?
  • Modify value of a Django form field during clean() and validate again
  • Heroku Django app can't start up -- 'No module named site'
  • Getting list of dates (excluding weekends)
  • Im trying to create the regular expression to include the text and not the href
  • Python file.readline(2) reads first 2 charectars
  • Groupby with handling empty bin in python
  • Modifying Gcode
  • calling a value in a dictionary within a dictionary (reading a json file)
  • Bouncing ball invalid syntax why is that?
  • Python making a counter
  • Python rstrip and split
  • What does the String mean in numpy.r_?
  • How to correctly extend variable __all__ in a __init__.py?
  • Python behaves weird with piped input
  • Python 3 two dimensional list comprehension
  • How to slice image by broadcasting slices? Error: 'only integer scalar arrays can be converted to a scalar index' in pyt
  • (Python Beginner) Need a start on classes
  • IndexError: At least one sheet must be visible
  • How to solve a system of linear equations over the nonnegative integers?
  • Pandas keep the most complete rows
  • "List index out of range" error in Python Memory Match game
  • Numpy: how to use argmax results to get the actual max?
  • Google Cloud Dataflow can't import 'google.cloud.datastore'
  • Calculate pandas DataFrame column by custom routine which accepts dictionary as input
  • Connect to a Class Method by it's method name holded into a var in a for loop in python
  • PyQt5 signals and threading.Timer
  • Replace 2 characters in a string in python
  • Passing command line arguments from a folder script to a file script
  • Understand the syntaxe X[Y == c] in Numpy
  • Optimize beginner python script about substring replacement
  • shadow
    Privacy Policy - Terms - Contact Us © voile276.org