Multiple widgets in one item

41 Views Asked by At

I try to add multiple widgets in one listitem. I have a listwidget with listitems. The listitems contains an icon and text. I try to get the filename of the icon back instead of the text and want to add a button and a lineedit to the same item. So you have a icon with a button and a text field in place of the default text (under the icon). I can't find usefull examples and nothing I tried worked so Is something possible? Or am I using the wrong widget for this? I'm a noob at python/pyqt.

def additems(self):

    image = QtGui.QPixmap("C:/Users/Gebruiker/Pictures/jack.jpg")

    for i in range(10):
        icon = QtWidgets.QListWidgetItem(QtGui.QIcon(image), "Item " + str(i))
        self.listWidget.addItem(icon)

        item = QtWidgets.QListWidgetItem()

        line = QtWidgets.QLineEdit(textChanged = self.textChanged)

        button = QtWidgets.QPushButton("Button " + str(i), clicked=self.buttonClicked)

        cellwidget = QtWidgets.QWidget()
        layout = QtWidgets.QHBoxLayout()

        layout.addWidget(line)
        layout.addWidget(button)

        cellwidget.setLayout(layout)
        cellwidget.show() # This is showing the widget with the line and button, but it open en close the window 10(Range of for loop) times. Widget disapears when resizing window.

        self.listWidget.setItemWidget(icon, cellwidget)

Edit: Updatet the code.

0

There are 0 best solutions below