我正在尝试自定义qlistwidgetitem,但是文本和按钮之间存在重叠。
这是我的代码。
from PyQt4.QtGui import *
from PyQt4.QtCore import *
import sys
class myListWidget(QListWidget):
def Clicked(self, item):
QMessageBox.information(self, "ListWidget", "You clicked: "+item.text())
def main():
app = QApplication(sys.argv)
listWidget = myListWidget()
#Resize width and height
listWidget.resize(300,120)
l = QListWidgetItem()
l.setText('Im an item')
l.setFlags(l.flags() | Qt.ItemIsUserCheckable)
l.setCheckState(Qt.Checked)
button = QCheckBox('Hello')
l.setSizeHint(button.minimumSizeHint())
listWidget.addItem(l)
listWidget.setItemWidget(l, button)
listWidget.setWindowTitle('PyQT QListwidget Demo')
listWidget.itemClicked.connect(listWidget.Clicked)
listWidget.show()
sys.exit(app.exec_())
if __name__ == '__main__':
main()
要求:-