Skip to main content

pyqt-editable-list-widget

Easily editable QListWidget

General Info

In this QListWidget, persistent editor is automatically activated/deactivated when calling the addItem.

Persistent editor will be closed if you press enter or up or down key or click somewhere else after editing.

If you want to add the item consecutively, use setConsecutiveAddWhenEnterPressed(f: bool). You can add a new item again.

You can edit existing items to double-click it or press F2.

You have to call closeIfPersistentEditorStillOpen() before addItem. If you don't, old editor still remain open even though new editor was already opened.

Requirements

PyQt5 >= 5.8

Setup

python -m pip install pyqt-editable-list-widget

Code Example

import sys



from PyQt5.QtCore import Qt

from PyQt5.QtGui import QIcon

from PyQt5.QtWidgets import QPushButton, QApplication, QCheckBox, QDialog,



QVBoxLayout, QListWidgetItem, QWidget, QHBoxLayout, QLabel

from pyqt_editable_list_widget import EditableListWidget





class Dialog(QDialog):

    def __init__(self):

        super().__init__()

        self.__initUi()



    def __initUi(self):

        # topWidget start

        lbl = QLabel('Files')

        lay = QHBoxLayout()

        lay.setAlignment(Qt.AlignLeft)

        lay.addWidget(lbl)

        lay.setContentsMargins(0, 0, 0, 0)



        topWidget = QWidget()

        topWidget.setLayout(lay)

        # topWidget end



        # middleWidget start

        allChkBox = QCheckBox('Check All')



        left_lay = QHBoxLayout()

        left_lay.setAlignment(Qt.AlignLeft)

        left_lay.addWidget(allChkBox)

        left_lay.setContentsMargins(0, 0, 0, 0)



        btn_style = '''

        QPushButton 

        {

        border:0; 

        background:transparent;

        padding:1px;

        }

        QPushButton:hover

        {

        background-color:#DDDDDD;

        border-radius: 2px;

        }

        QPushButton:pressed

        {

        background-color:#FFFFFF;

        border-radius: 2px;

        }

        QPushButton:checked

        {

        background-color: rgb(210, 210, 210);

        border-radius: 2px;

        border: none;

        }

        '''



        addBtn = QPushButton()

        addBtn.clicked.connect(self.__add)

        addBtn.setStyleSheet(btn_style)

        addBtn.setIcon(QIcon('./ico/add.png'))

        addBtn.setToolTip('Add')



        delBtn = QPushButton()

        delBtn.clicked.connect(self.__delete)

        delBtn.setStyleSheet(btn_style)

        delBtn.setIcon(QIcon('./ico/delete.png'))

        delBtn.setToolTip('Delete')



        right_lay = QHBoxLayout()

        right_lay.setAlignment(Qt.AlignRight)

        right_lay.addWidget(addBtn)

        right_lay.addWidget(delBtn)

        right_lay.setContentsMargins(0, 0, 0, 0)



        lay = QHBoxLayout()

        lay.addLayout(left_lay)

        lay.addLayout(right_lay)

        lay.setContentsMargins(0, 0, 0, 0)



        middleWidget = QWidget()

        middleWidget.setLayout(lay)

        # middleWidget end



        # bottomWidget

        self.__bottomWidget = EditableListWidget()



        # mainWidget start

        lay = QVBoxLayout()

        lay.addWidget(topWidget)

        lay.addWidget(middleWidget)

        lay.addWidget(self.__bottomWidget)

        lay.setContentsMargins(0, 0, 0, 0)



        mainWidget = QWidget()

        mainWidget.setLayout(lay)



        lay = mainWidget.layout()

        lay.setContentsMargins(5, 5, 5, 5)



        self.setLayout(lay)

        # mainWidget end



    def __add(self):

        self.__bottomWidget.closeIfPersistentEditorStillOpen()  # You have to call this.

        item = QListWidgetItem('abc')

        self.__bottomWidget.addItem(item)



    def __delete(self):

        item = self.__bottomWidget.currentItem()

        if item:

            self.__bottomWidget.takeItem(self.__bottomWidget.currentRow())





if __name__ == "__main__":

    app = QApplication(sys.argv)

    dialog = Dialog()

    dialog.show()

    sys.exit(app.exec_())

Metadata

Release files for pyqt-editable-list-widget 0.0.11

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for pyqt-editable-list-widget 0.0.11
File Size Uploaded
pyqt-editable-list-widget-0.0.11.tar.gz 4.0 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for pyqt-editable-list-widget 0.0.11
File Interpreter ABI Platform
pyqt_editable_list_widget-0.0.11-py3-none-any.whl Python 3 none any Details

Total release size: 8.5 kB

Release files / pyqt-editable-list-widget-0.0.11.tar.gz

Download URL pyqt-editable-list-widget-0.0.11.tar.gz
Size 4.0 kB
Tags Source
SHA-256 checksum
How to use checksums
f00054bde5c187e2a249e3fb0f8ff96a33fe20a8dac2371676082a64a38de2c5
BLAKE2b-256 checksum
How to use checksums
b39e4500a3b5a729ccfe73b588c15d6f80d40bca4eb9c40cd80546b4ea68ad8b
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/0.0.0 CPython/3.7.6

Release files / pyqt_editable_list_widget-0.0.11-py3-none-any.whl

Download URL pyqt_editable_list_widget-0.0.11-py3-none-any.whl
Size 4.5 kB
Tags Python 3
SHA-256 checksum
How to use checksums
395f0390e6aa9640050b4f9658704c05af901568cf43bac0540df3748c8bc6bb
BLAKE2b-256 checksum
How to use checksums
2f44d026e4af3a0a0c34e01db5433b91a41e36557cccf7d73c4486973b404aad
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/0.0.0 CPython/3.7.6

Release history Release notifications | RSS feed

This release

0.0.11 This release

2 release files

0.0.1

2 release files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page