0

I am creating SpinBox and then I am trying to make it visible inside my MainWindow. Is it any way to do it? Basically I am creating double array of Spinboxes dynamically in loop like this
array=new QSpinBox *[y+1];
and in another loop like this
array[i]=new QSpinBox[x+1]; which works fine. And now I'd like to show it on main window,with geometry set.
When I do
array[i][j].show()
It generates new windows. Is there a way to do it?

Ps. Basically I want to generate Matrix on screen, so when user press button it switch from 2x2 SpinBoxes to 3x3 SpinBoxes. So in
void MainWindow::on_pushButton_clicked()
I want to generate SpinBoxes on MainWindow. \

Thanks for help

Mike
  • 1
  • You should add the spinboxes to a layout like `QGridLayout`. Then, assign that layout to a `QWidget`. Then, make that widget your main window's central widget by calling `QMainWindow::setCentralWIdget()`. https://doc.qt.io/qt-5/qmainwindow.html#details – Minh Nov 20 '20 at 11:46
  • About the changing button, you can store the spinboxes in the third row and column somewhere. When the button is clicked, toggle there visibility using `QWidget::setHidden()` or `QWidget::setVisible()` – Minh Nov 20 '20 at 11:51
  • Can I manipulate geometry of setCentralWIdget()? I mean can I set size and x,y position? – Mike Nov 20 '20 at 12:01
  • You can only set size of the central widget if you set a fixed size, otherwise it will be determine by the main window. I don't think you can set the x, y position in Qt widgets at all. If you want to get that accurate, you can set a fixed size for your widgets, then play with the layout's content margin, spacing, and size constraint. https://doc.qt.io/qt-5/qlayout.html#sizeConstraint-prop – Minh Nov 20 '20 at 12:09

0 Answers0