【pyqt】listwidget中的删除按钮

python 复制代码
    def create_custom_widget(self, text):
        widget = QWidget()
        widget.setStyleSheet("QWidget{border-bottom: 3px solid white;"
                             "border-top: 2px solid white;}")
        layout = QVBoxLayout()
        label = QLabel(text)
        label.setStyleSheet("background-color:transparent;"
                            "border-bottom:0px;border-top: 0px;")
        current_time = QDateTime.currentDateTime().toString(Qt.DefaultLocaleShortDate)

        label2 = QLabel(f"{current_time}")
        label2.setStyleSheet("background-color:transparent;"
                             "border-bottom:0px;border-top: 0px;")
        deleteBtn = QPushButton("删除")
        deleteBtn.setStyleSheet("QPushButton{background-color:transparent;"
                                "border-bottom:0px;border-top: 0px;}"
                                "QPushButton::hover{color:red;}")
                                
        deleteBtn.clicked.connect(self.remove_item)  # 连接信号和槽

        h_layout = QHBoxLayout()
        h_layout.addWidget(label2)
        h_layout.addWidget(deleteBtn)
        h_layout.setStretch(0, 1)
        h_layout.setStretch(1, 0)

        layout.addWidget(label)
        layout.addLayout(h_layout)
        widget.setLayout(layout)
        return widget

    # 定义移除列表项的槽函数
    def remove_item(self):
        button = self.sender()  # 获取发出信号的按钮
        if button:
            row = self.listWidget.indexAt(button.parent().pos()).row()
            # 从列表视图中移除项
            self.listWidget.takeItem(row)

tablewiget是removeRow

python 复制代码
            self.tableWidget.removeRow(row)
相关推荐
懷淰メ18 小时前
【AI加持】基于PyQt+YOLO+DeepSeek的车型检测系统(详细介绍)
yolo·目标检测·计算机视觉·pyqt·项目设计·deepseek·车型检测
淮北4942 天前
ubuntu22.04将mp4转换成gif
python·scrapy·flask·beautifulsoup·pyqt·matplotlib
懷淰メ3 天前
【AI加持】基于PyQt+YOLO+DeepSeek的口罩佩戴检测系统(详细介绍)
yolo·计算机视觉·pyqt·口罩检测·deepseek·ai加持
小灰灰搞电子5 天前
PyQt QWebChannel详解-C++与Web页面的无缝双向通信
前端·pyqt
小灰灰搞电子7 天前
PyQt QtAwesome详解:为Qt应用注入字体图标的魅力
pyqt·字体图标
DeepLearningYolo7 天前
基于PyQt的YOLOv5+DeepSORT可视化界面,可实现目标跟踪、模型更换、结果保存和轨迹隐藏等功能。
yolo·目标跟踪·pyqt
TRACER~8512 天前
项目实战:pyqt6实现拼豆图纸生成器
python·pyqt
龙腾AI白云21 天前
大模型Prompt实战:精准生成专业技术文档
plotly·pyqt·fastapi·tornado·dash
CodebySandwich25 天前
QWidget转化为matplotlib绘图窗体
pyqt
懷淰メ25 天前
python3GUI---基于PyQt5+YOLOv8+DeepSort的智慧行车可视化系统(详细介绍)
开发语言·yolo·计算机视觉·pyqt·yolov8·deepsort·车距