77 lines
2.1 KiB
Python
77 lines
2.1 KiB
Python
from PyQt5.QtCore import *
|
|
from PyQt5.QtGui import *
|
|
from PyQt5.QtWidgets import *
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
# font: 25 9pt "Microsoft YaHei";
|
|
|
|
class select_list(QObject):
|
|
style_sheet ="""
|
|
QListView {
|
|
font: 25 9pt;
|
|
border: 15px solid white;
|
|
border-radius: 10px;
|
|
show-decoration-selected: 1;
|
|
}
|
|
QListView::item {
|
|
height: 40px;
|
|
}
|
|
QListView::item:hover {
|
|
background-color: transparent;
|
|
padding: 10px;
|
|
border-left: 3px solid rgb(130, 130, 130);
|
|
}
|
|
QListView::item:selected {
|
|
background-color: transparent;
|
|
color: black;
|
|
padding: 10px;
|
|
border-left: 3px solid black;
|
|
}
|
|
"""
|
|
def __init__(self,father:QDialog,title:str,str_list:list):
|
|
QObject.__init__(self)
|
|
self.w=QDialog(father)
|
|
self.w.resize(800,400)
|
|
self.w.setWindowTitle(title)
|
|
self.w.setAttribute(Qt.WidgetAttribute.WA_DeleteOnClose)
|
|
self.w.setWindowModality(Qt.WindowModality.ApplicationModal)
|
|
|
|
self.file_list = QListWidget(self.w)
|
|
self.file_list.setObjectName(u"str_list")
|
|
self.file_list.setGeometry(QRect(20, 20, 760, 360))
|
|
self.file_list.setFrameShape(QFrame.Shape.Box)
|
|
self.file_list.setMidLineWidth(1)
|
|
self.file_list.setVerticalScrollBarPolicy(Qt.ScrollBarPolicy.ScrollBarAsNeeded)
|
|
self.file_list.setSelectionMode(QAbstractItemView.SelectionMode.SingleSelection)
|
|
self.file_list.itemDoubleClicked.connect(self.item_clicked)
|
|
self.file_list.setStyleSheet(self.style_sheet)
|
|
self.item_append(str_list)
|
|
|
|
def item_append(self,items:list):
|
|
for i in items:
|
|
# print("add item",i[0])
|
|
self.file_list.addItem(i[0])
|
|
def item_clicked(self,item:QListWidgetItem ):
|
|
self.select_item=item.text()
|
|
self.w.done(QDialog.DialogCode.Accepted)
|
|
self.w.close()
|
|
def show(self):
|
|
# self.w.show()
|
|
if(self.w.exec()==QDialog.DialogCode.Accepted):
|
|
# print(self.select_item)
|
|
return self.select_item
|
|
return ""
|
|
|
|
|
|
|
|
|
|
|
|
|