enum WidgetType { WIDGET_0, WIDGET_1, WIDGET_2, WIDGET_3, WIDGET_4, WIDGET_5,};class QMyWidget : public QWidget {...private: WidgetType widgetType;public: WidgetType getWidgetType() { return widgetType; }}
C++ (Qt)void MyClass::show_wgt(QWidget *w, x, y, w, h){ if (qobject_cast<QLabel *>(w)) qobject_cast<QLabel *>(w)->setText(lineName->text()); else if (qobject_cast<QPushButton *>(w)) qobject_cast<QPushButton *>(w)->setText(lineName->text()); w->setStyleSheet("QWidget {background-color: red}"); w->setGeometry(x, y, w, h); w->show();} void MyClass::set_showedWidget(){ int x, y, w, h; x = 20; y = 45; w = 70; h = 25; QWidget *toShow = 0; if (qobject_cast<QLabel *>(sender()) { // do something toShow = new QLabel(this); } else if (qobject_cast<QPushButton *>(sender()) { // do something toShow = new QPushButton(this); } else { // wrong type return; } show_wgt(toShow , x, y, w, h);}