Placing a Widget several times with different values

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,

What I’ve done with a widget that’s updated manually through code is apply the setting you want and set it’s class name (setproperty(“class”, value)) to whatever. Then use CSS applied at the application level to change it’s appearance dynamically.

Thank you, in the meantime i learned alot more. Im still in the discovery mode but in terms of repeating, i hvae now my own modul i call “GlobalSettings” in which i just store global variables and pull them for QSize, etc. from one source. I abandoned the move(x,y) idea and thinking of writing a function which creates the data and use outcome - somehow to infuse it into an xxx.addWidget or xxx.addLayout and repeat that on an existing QGridlayout. No idea how precxisely, but i think this thought is worth investigating. Thanks!