栏目分类:
子分类:
返回
名师互学网用户登录
快速导航关闭
当前搜索
当前分类
子分类
实用工具
热门搜索
名师互学网 > IT > 面试经验 > 面试问答

将小部件添加到qtablewidget pyqt

面试问答 更新时间: 发布时间: IT归档 最新发布 模块sitemap 名妆网 法律咨询 聚返吧 英语巴士网 伯小乐 网商动力

将小部件添加到qtablewidget pyqt

您有几个问题可以归结为一个…简短答案,是的,您可以向QTableWidget添加按钮-
您可以通过调用setCellWidget将任何窗口小部件添加到表格窗口小部件:

# initialize a table somehowtable = QTableWidget(parent)table.setRowCount(1)table.setColumnCount(1)# create an cell widgetbtn = QPushButton(table)btn.setText('12/1/12')table.setCellWidget(0, 0, btn)

但这听起来并不像您真正想要的。

听起来您想对用户双击一个单元格做出反应,就像他们单击了一个按钮一样,大概是要弹出对话框或编辑器之类的东西。

在这种情况下,您真正​​需要做的就是从QTableWidget连接到itemDoubleClicked信号,如下所示:

def editItem(item):    print 'editing', item.text()# initialize a table widget somehowtable = QTableWidget(parent)table.setRowCount(1)table.setColumnCount(1)# create an itemitem = QTableWidgetItem('12/1/12')table.setItem(0, 0, item)# if you don't want to allow in-table editing, either disable the table like:table.setEditTriggers( QTableWidget.NoEditTriggers )# or specifically for this itemitem.setFlags( item.flags() ^ Qt.ItemIsEditable)# create a connection to the double click eventtable.itemDoubleClicked.connect(editItem)


转载请注明:文章转载自 www.mshxw.com
本文地址:https://www.mshxw.com/it/624596.html
我们一直用心在做
关于我们 文章归档 网站地图 联系我们

版权所有 (c)2021-2022 MSHXW.COM

ICP备案号:晋ICP备2021003244-6号