how to add a QListWidgetItem on top of the QListWidget?

Viewed 3463

I am trying to create something like a layer editor that you normally see in most of the image editor softwares, and for this I need to add the new layers on the top of the QListWidget, the code that I'm currently trying is this one:

def new_layer(self):

    layer = Layer(layer_name="Layer %d" % self.number_of_layers)
    layer_item = QListWidgetItem(self)
    layer_item.setSizeHint(layer.sizeHint())

    if self.number_of_layers % 2 == 0:
        layer_item.setBackground(Qt.darkGray)
    else:
        layer_item.setBackground(Qt.gray)

    self.setItemWidget(layer_item, layer)
    self.insertItem(0, layer_item)

    self.number_of_layers += 1

even after inserting the QListWidgetItem in the row 0, when the new layer is added it is displayed beneath the first layer that was previously created. What could I do to fix it?

1 Answers
Related