1

I'm trying to dynamically add spinboxes but I need them to be on a different tab which I have created in the designer. Is it possible for me to add them to a tab instead of the main window?

QSpinBox *spin[10]; for (int i=0; i < 10; i++) { spin[i] = new QSpinBox(this); spin[i]->setValue(i); spin[i]->setGeometry(QRect(QPoint(100,100),QSize(50,50))); //todo: change position spin[i]->show(); }

1
  • so are you using a QTabWidget? Commented Jan 28, 2016 at 3:48

1 Answer 1

2

When you create the QSpinBox, use the tab as the parent.

In your example you are using this, which I'm going to assume is the widget you've designed in the designer.

As an example, if you had an empty widget in the designer and dragged a QTabWidget onto it, it will create a QTabWidget called tabWidget. By default it has two tabs (which are QWidgets) called tab and tab_2. Also, by default, the designer creates a member variable in your class called ui which represents your widget.

Therefore, to add a QSpinBox to the tab, in code, you would do the following:

QSpinBox* spinBox = new QSpinBox(ui->tab);

This has set the parent of the spin box to ui->tab instead of this.

Sign up to request clarification or add additional context in comments.

1 Comment

That was it, I was close! Thank you!

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.