Widget Ownership
-
Just starting so checking a thing:
If I create an widget in mainwindow then mainwindow will normally own it and I can refer to it as eg plainTextEdit within mainwindow's functions. Yes?
If I create a widget via the designer then it would seem that the ui owns it and I always have to refer to it as ui->plainTextEdit. Is that right? It seems a bit cumbersome. Perhaps I've got it wrong. Perhaps there's a better way to do things. Perhaps there's some kind of shortcut or reference mechanism. I am a bit puzzled. -
Hi,
When creating a complex widget using Designer, yes, you have to use ui->plainTextEdit since that class is generated from the XML built by Designer.
Is it cumbersome ? It's rather a question of whether you like to build your UI using Designer or do everything by hand. No, there's no shortcut to avoid
ui->somethingwhen you want to do something with an element of that widget.If that's something you really don't like it, then you have the alternative to write your own widget completely by hand. It really is just a matter of taste.
-
Frankly, that will just add clutter to your code and make it less understandable when you (or someone else) re-read it later.
-