If I want to use "setCentralWidget" in Widget, what should I do.
Unsolved
General and Desktop
-
I am now porting the sample code of QCustomPlot. The sample code of QCustomPlot uses QMainWindow, and I want to use QWidget. What should I do?
this is my code
Widget::Widget(QWidget *parent) : QWidget(parent) , ui(new Ui::Widget), mPlot(0), mTag1(0), mTag2(0) { ui->setupUi(this); mPlot = new QCustomPlot(this); setCentralWidget(mPlot); }
this is QCustomPlot`s sample code
MainWindow::MainWindow(QWidget *parent) : QMainWindow(parent), ui(new Ui::MainWindow), mPlot(0), mTag1(0), mTag2(0) { ui->setupUi(this); mPlot = new QCustomPlot(this); setCentralWidget(mPlot); }
Please help me!😭😭
-
You can only use setCentralWidget with a QMainWindow. Instead use QWidget::setLayout to add a layout and then add a QWidget to the layout.
See the documentation for QWidget::setLayout.
-
Hi and welcome to devnet,
The answer of @skycrestway still holds. Your widget needs a layout. After that you can add your plot to that layout.