View Full Version : passing variables in a QWidget constructor when programming with QTDesigner

16th October 2006, 13:16
Hello everyone,
i am programming in Qt Designer and i want during the QWidget::init() call to pass some variables of my own.. but QtDesigner does not give you anyway to tamper with the form constructor.. and i do not want to affect directly the generated .h and .cpp files under folder .ui/ since they can be overwritten. Is there somethng else i can do?

16th October 2006, 14:54
Yes, use the subclassing approach (http://doc.trolltech.com/3.3/designer-manual-6.html).

17th October 2006, 19:25
Maybe not the best way to do it, but pretty easy. You can write a public method for your Widget, and send your parameters when you call this special method. Maybe a little example can be better:

// Somewhere in code, create an instance of some widget
viewer = new Viewer(frame3D, "graf");
// we need to send X and Y dynamic sizes, so:
viewer->param(sizeX, sizeY);
// put 'viewer' on screen...

Note that we call param() before actually showing the widget. This way
param executes just after construct, and after init(), but before the widget is shown.

Class Viewer, must have a public method param():

void Viewer::param(int X, int Y) {....}

Hope this aproach can help someone.