0

I used Qt Designer to make two .ui files, one is the Main Window of my application, and the second is a custom widget I made. My idea was to fill a listWidget on my Main application with this custom Widget to display data.

I made this code, which compiles without problem but it does not show the customWidget on the List when it runs

import sys 
from PyQt5.QtWidgets import QMainWindow, QApplication, QPushButton, QWidget, QAction, QTabWidget,QVBoxLayout,QDialog
from PyQt5 import QtCore, QtGui, QtWidgets
from mainwindowReclamo import Ui_MainWindow
from widgetReclamos import Ui_Form
#Custom Widget*
class WidgetReclamo(QWidget, Ui_Form):
 """docstring for ClassName"""
 def __init__(self,*args,**kwargs):
 QWidget.__init__(self,*args,**kwargs)
 self.setupUi(self)
 print("I am Alive")
 
#My Main Program*
class ProgramaReclamos(QMainWindow, Ui_MainWindow): 
 def __init__(self,*args,**kwargs):
 QMainWindow.__init__(self,*args,**kwargs)
 self.setupUi(self)
 #I create an Item*
 Item = QtWidgets.QListWidgetItem(self.listWidget)
 #I create a custom widget*
 Item_Widget = WidgetReclamo()
 #I set the Size from the Item to the same of the widget*
 Item.setSizeHint(Item_Widget.sizeHint())
 #I add it to the list*
 self.listWidget.addItem(Item)
 self.listWidget.setItemWidget(Item, Item_Widget)
 
if __name__ == '__main__':
 app = QApplication(sys.argv)
 prog = ProgramaReclamos()
 prog.show()
 sys.exit(app.exec_())

I saw some questions online which their answer were for PyQt4 and they said something about using a Layout for the Widget, but I don ́t understand if I have to make one because the widget was made in the .ui file

Jason Aller
3,66028 gold badges42 silver badges40 bronze badges
asked Nov 10, 2017 at 0:48
3
  • Execute this: print(Item_Widget.sizeHint()) Commented Nov 10, 2017 at 0:59
  • Change Item.setSizeHint(Item_Widget.sizeHint()) to Item.setSizeHint(Item_Widget.size()) Commented Nov 10, 2017 at 1:03
  • My god, it worked. Man, thank you so much! you have helped me two times in a row! Commented Nov 10, 2017 at 1:12

1 Answer 1

1

As EYLLANESC said on the comment:

Change Item.setSizeHint(Item_Widget.sizeHint()) to Item.setSizeHint(Item_Widget.size()) – eyllanesc

Thank you !

answered Nov 10, 2017 at 3:29
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

By clicking "Post Your Answer", you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.