2
votes

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?

1
You should get into the habit of naming class names with a capital letter for each new word. childofwidget should be named ChildOfWidget. Variables and method names should begin with a lower letter and capital letter for every new word: mainlayout should be named mainLayout. (This is the Qt naming convention.) - leemes

1 Answers

5
votes

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