# !-*- coding:utf-8 -*- import os import sys from PyQt5 import uic from PyQt5.QtCore import Qt from PyQt5.QtWidgets import QDialog, QApplication, QListWidgetItem # ui 파일명과 소스 파일명 동일하게 저장(_name, _ext) = os.path.splitext(os.path.basename(__file__)) _ui_path = os.path.join('./', _name + '.ui') FORM_CLASS, _ = uic.loadUiType(_ui_path) class DemoListWidget(QDialog, FORM_CLASS): """ https://doc.qt.io/qt-5/qlistwidget.html https://doc.qt.io/qt-5/qlistwidgetitem.html """ def __init__(self): super().__init__() self.setupUi(self) # ListWidget 에 데이터 추가. self._init_data() self.listWidget.currentItemChanged.connect(self.cb_currentItemChanged) self.listWidget.currentRowChanged.connect(self.cb_currentRowChanged) self.listWidget.currentTextChanged.connect(self.cb_currentTextChanged) self.listWidget.itemActivated.connect(self.cb_itemActivated) self.listWidget.itemChanged.connect(self.cb_itemChanged) self.listWidget.itemClicked.connect(self.cb_itemClicked) def _init_data(self): _item = QListWidgetItem() _item.setData(Qt.DisplayRole, 'hello') _item.setData(Qt.UserRole, 'world') # checkbox 플래그 설정. _item.setFlags(_item.flags() | Qt.ItemIsUserCheckable) # checkbox 초기값 설정 Qt.Unchecked : 0, Qt.PartiallyChecked : 1, Qt.Checked : 2 _item.setCheckState(Qt.Unchecked) # 위젯에 아이템 추가. self.listWidget.addItem(_item) def cb_currentItemChanged(self, _current, _previous): print('cb_currentItemChanged') def cb_currentRowChanged(self, _currentRow): print('cb_currentRowChanged') def cb_currentTextChanged(self, _currentText): print('cb_currentTextChanged') def cb_itemActivated(self, _item): print('cb_itemActivated') def cb_itemChanged(self, _item): """ 체크박스를 체크, 해제 했을 때 호출됨. :param _item: :return: """ # hello 출력 print(_item.text()) # hello 출력 print(_item.data(Qt.DisplayRole)) # world 출력 print(_item.data(Qt.UserRole)) # 체크 해제 : 0, 체크 : 1 print(_item.checkState()) # 아이템의 row num _row = self.listWidget.row(_item) print(_row) # 아이템 수 print(self.listWidget.count()) # 아이템 제거. _taken_item = self.listWidget.takeItem(_row) # 아이템 수 print(self.listWidget.count()) def cb_itemClicked(self, _item): print('cb_itemClicked') def main(): app = QApplication(sys.argv) dialog = DemoListWidget() dialog.show() app.exec_() if __name__ == '__main__': main()
2018년 11월 14일 수요일
[PyQt5] QListWidget demo
피드 구독하기:
글 (Atom)
docker redmine 설치
docker-composer.yml version: '3.1' services: redmine: image: redmine restart: always container_na...
-
용량이 큰 파일 업로드 시 net::ERR_CONNECTION_RESET 오류 발생할 경우. http_server = tornado.httpserver.HTTPServer(app, max_buffer_size=10485760000) upload_for...
-
docker-composer.yml version: '3.1' services: redmine: image: redmine restart: always container_na...
-
# !-*- coding:utf-8 -*- import os import sys from PyQt5 import uic from PyQt5.QtCore import Qt from PyQt5.QtWidgets import QDialog , QAppl...