qt - Add QWidget to QListWidget -
qt - Add QWidget to QListWidget -
i trying create qlistwidget in each item simple widget contains text , pushbutton. utilize following:
itemn = qtgui.qlistwidgetitem() #create widget widget = qtgui.qwidget() widgettext = qtgui.qlabel("i love pyqt!") widgetbutton = qtgui.qpushbutton("push me") widgetlayout = qtgui.qhboxlayout() widgetlayout.addwidget(widgettext) widgetlayout.addwidget(widgetbutton) widgetlayout.addstretch() widget.setlayout(widgetlayout) #add widget qlistwidget funlist funlist.additem(itemn) funlist.setitemwidget(itemn, widget)
the problem is, nil shows up. blank line can navigate using keyboard, blank. when widget contains just pushbutton, works, isn't if pushbutton lone messing things up. there limits on complexity of widgets setitemwidget
can handle? perhaps need go beyond convenience classes, suggested in of related posts below?
related posts
pyqt adding widget qlistwidget note previous post has similar title mine, seems relatively poorly expressed question complex pastiche of code qtdesigner (mixed custom stuff). not clear @ question person should have been asking. while title makes seem duplicate, question (i pray) not.
i similar this post.
qlistwidgetitem radio button
qlistview/qlistwidget custom items
adding custom widget qlistwidget in qt click issue in qt?
pyqt adding widget qlistwidget
http://www.qtcentre.org/threads/8660-drawing-a-widget-in-qitemdelegate-s-paint-method
http://developer.nokia.com/community/discussion/showthread.php/211634-adding-a-button-inside-qlistwidgetitem
try this:
itemn = qtgui.qlistwidgetitem() #create widget widget = qtgui.qwidget() widgettext = qtgui.qlabel("i love pyqt!") widgetbutton = qtgui.qpushbutton("push me") widgetlayout = qtgui.qhboxlayout() widgetlayout.addwidget(widgettext) widgetlayout.addwidget(widgetbutton) widgetlayout.addstretch() widgetlayout.setsizeconstraint(qtgui.qlayout.setfixedsize) widget.setlayout(widgetlayout) itemn.setsizehint(widget.sizehint()) #add widget qlistwidget funlist funlist.additem(itemn) funlist.setitemwidget(itemn, widget)
as can see, need setsizeconstraint
layout , setsizehint
item.
qt qt4 pyqt pyqt4 pyside
Comments
Post a Comment