Hello Guys,
Im currently try to cleanup my code and want to separate the function from the code, which i mostly achived.
Now i want to reuse the widget which shows a random name by creating a subclass from QGridLayout and add a function here:
class set_widgets(QGridLayout):
# Set Name Widget
def set_npcname(self, xpos, ypos):
layout = QGridLayout()
self.npcavname = QLabel()
self.avname = npcbuild.generate_name()
print("npcbuild.generate_name:",self.avname)
print(inspect.currentframe().f_code.co_name)
self.npcavname.update()
#self.npcavname.setFixedWidth(250)
self.npcavname.setStyleSheet("font: bold New Courier")
#self.npcavname.setStyleSheet("background-image: url(:./icons/charbanner.png);")
self.npcavname.setText(self.avname)
self.npcavname.move(xpos, ypos)
#self.npcavname.move(300, 80)
self.npcavname.adjustSize()
self.addWidget(self.npcavname)
placewidget = set_widgets()
I want do to this to clean up my main program or the InitUi function.
Now the only usecase for me is, i want to put this widget as a reusable task several times across my window (Qwidget) by changing or adapting the x and y position.
So programming once, but using it many times.
I call then the widget. which produces a random name via npcbuild.generate_name() with:
placewidget.set_npcname(300,80) which i do in my main program.
So the widget is not shown anywhere. I’m struggling to understand which of the function part needs to be in the main program and which part can be put in a class / function?
I tried inheriting the addWidget(self.npcavname) by creating a subclass of QGridslayout but so far no luck.
Any ideas on how to solve this?
thanks,
best,