Frage

Not sure if I'm even asking this question correctly because I'm new to C++ and Qt. But, say I have a subclass of QWidget:

class childofqwidget : public QWidget

Can I pass a pointer to an object of subclass to the setCentralWidget member function of QMainWindow? Something like this:

mainlayout = new childofqwidget;
setCentralWidget(mainlayout);

The reason I'm asking is because I've made a subclass of QWidget which has a layout with a textbox and some buttons. I'd like to insert this as the central widget of the QMainWindow object. Is this possible? If not is there a better way I should do this?

War es hilfreich?

Lösung

Yes that's perfectly fine, and that's the usual way to do it.

(Call a variable layout when it's a widget is a bit unusual/confusing though, but that's just naming.)

Lizenziert unter: CC-BY-SA mit Zuschreibung
Nicht verbunden mit StackOverflow
scroll top