JustinBlaber
JustinBlaber

Reputation: 4660

Using setCentralWidget on a subclass of QWidget?

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?

Upvotes: 2

Views: 5203

Answers (1)

Mat
Mat

Reputation: 206879

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.)

Upvotes: 5

Related Questions