PyQt: is there an better way to set objectName in code?

后端 未结 1 1904
星月不相逢
星月不相逢 2021-01-24 23:31

When you use Qt_Designer or Qt_Creator to design a form, objectName for any given widget is always set to something. But if you create a widget in code AND you need the objectNa

相关标签:
1条回答
  • 2021-01-25 00:13
    button1 = QPushButton('button caption', objectName='button1')
    

    You can extend this to any Qt property during initialization:

    button1 = QPushButton(text='button caption', objectName='button1', icon=icon1)
    

    Moreover, signals can be connected when constructing an object, too:

    button1 = QPushButton(text='button caption', objectName='button1', clicked=someMethod)
    

    The added named argument is equivalent to button1.clicked.connect(someMethod)

    0 讨论(0)
提交回复
热议问题