Easily editable list widget
Project description
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_())
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
File details
Details for the file pyqt-editable-list-widget-0.0.11.tar.gz
.
File metadata
- Download URL: pyqt-editable-list-widget-0.0.11.tar.gz
- Upload date:
- Size: 4.0 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/0.0.0 CPython/3.7.6
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | f00054bde5c187e2a249e3fb0f8ff96a33fe20a8dac2371676082a64a38de2c5 |
|
MD5 | e8215f22ec9e9326110f6d4077181be4 |
|
BLAKE2b-256 | b39e4500a3b5a729ccfe73b588c15d6f80d40bca4eb9c40cd80546b4ea68ad8b |
File details
Details for the file pyqt_editable_list_widget-0.0.11-py3-none-any.whl
.
File metadata
- Download URL: pyqt_editable_list_widget-0.0.11-py3-none-any.whl
- Upload date:
- Size: 4.5 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/0.0.0 CPython/3.7.6
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 395f0390e6aa9640050b4f9658704c05af901568cf43bac0540df3748c8bc6bb |
|
MD5 | ac2ab647f58794979d17af39149e6267 |
|
BLAKE2b-256 | 2f44d026e4af3a0a0c34e01db5433b91a41e36557cccf7d73c4486973b404aad |