3 widgets in only one central widget
-
Hi jsum, can you give me some example? Because I don't understand.
You think that i should create a pointer like QLed *led and then transforms it in a "children"? Sorry but i don't know how to do it...QLed *led_1 = new QLed(m_plot); QLed *led_2 = new QLed(m_plot);Or, if you want to use a common widget as central widget:
QWidget *centralWidget = new QWidget(); m_plot = new WHAT_EVER_IT_IS(centralWidget); QLed *led_1 = new QLed(centralWidget); QLed *led_2 = new QLed(centralWidget); // Set up layouts here setCentralWidget(centralWidget);In the code you posted your leds are not put on any widgets and the layout you're using for them is not set on any widget or other layout.
-
QLed *led_1 = new QLed(m_plot); QLed *led_2 = new QLed(m_plot);Or, if you want to use a common widget as central widget:
QWidget *centralWidget = new QWidget(); m_plot = new WHAT_EVER_IT_IS(centralWidget); QLed *led_1 = new QLed(centralWidget); QLed *led_2 = new QLed(centralWidget); // Set up layouts here setCentralWidget(centralWidget);In the code you posted your leds are not put on any widgets and the layout you're using for them is not set on any widget or other layout.
-
Hi,
Use the layouts you had before and put the main layout in the container widget.
-
Hi @SGaist,
sorry but i don't understand what you mean with "container widget".
I cannot write setCentralWidget(mainwidget) because qt give me an error@venale17 said in 3 widgets in only one central widget:
"container widget".
Hi
that is just a term for the widget holding it all.
From @jsulm code, its the centralWidgetQWidget *centralWidget = new QWidget(); // this is our "container widget" m_plot = new QCustomPlot(centralWidget); QLed *led_1 = new QLed(centralWidget); QLed *led_2 = new QLed(centralWidget); // Set up layouts here setCentralWidget(centralWidget);what error do you get from this code ?
-
Ok, maybe i understand:
i wrote this:MainWindow::MainWindow(QWidget *parent) : QMainWindow(parent), m_plot(new QCustomPlot), m_ui(new Ui::MainWindow), m_luce(new Luce(m_plot)), m_status(new QLabel), m_console(new Console), m_settings(new SettingsDialog), //! [1] m_serial(new QSerialPort(this)) //! [1] { //! [0] m_ui->setupUi(this); m_console->setEnabled(false); QWidget *centralWidget = new QWidget(); // this is our "container widget" m_plot = new QCustomPlot(centralWidget); m_luce = new Luce(centralWidget); // Set up layouts here QHBoxLayout *mainlayout = new QHBoxLayout(centralWidget); mainlayout->addWidget(m_plot); mainlayout->addWidget(m_luce); setCentralWidget(centralWidget); [...]I create a pointer m_luce that describes the features of the leds and, with your examples i reach a good solution:

-
Hi
Super.
But you create them twice which is not needed.you have
m_plot(new QCustomPlot), // you new them here
m_luce(new Luce(m_plot)),so you can just do
QWidget *centralWidget = new QWidget(); // this is our "container widget"
m_plot = new QCustomPlot(centralWidget);we have new them already
m_luce = new Luce(centralWidget);// Set up layouts here QHBoxLayout *mainlayout = new QHBoxLayout(centralWidget); mainlayout->addWidget(m_plot); mainlayout->addWidget(m_luce); -
Hi all,
I have the same problem again.
I don't change anything of the code, just the PC.
I reinstalled Qt and i noticed that:
and this, is the code that i wrote, with you're helps:
m_ui->setupUi(this); m_console->setEnabled(false); QWidget *centralWidget = new QWidget(); // creo un container widget che raccolga i widget che creerò // Set up layouts here QHBoxLayout *mainlayout = new QHBoxLayout(centralWidget); //imposto un layout orizzontale mainlayout->addWidget(m_plot); mainlayout->addWidget(m_luce); mainlayout->addStretch(); //aggiungo l'oggetto puntato da m_plot e m_luce all'interfaccia secondo il layout orizzontale setCentralWidget(centralWidget); setCentralWidget(centralWidget);Someone have any idea? How can i divide the central widget in two equal part, one for the plot and the other for the leds?
-
Hi all,
I have the same problem again.
I don't change anything of the code, just the PC.
I reinstalled Qt and i noticed that:
and this, is the code that i wrote, with you're helps:
m_ui->setupUi(this); m_console->setEnabled(false); QWidget *centralWidget = new QWidget(); // creo un container widget che raccolga i widget che creerò // Set up layouts here QHBoxLayout *mainlayout = new QHBoxLayout(centralWidget); //imposto un layout orizzontale mainlayout->addWidget(m_plot); mainlayout->addWidget(m_luce); mainlayout->addStretch(); //aggiungo l'oggetto puntato da m_plot e m_luce all'interfaccia secondo il layout orizzontale setCentralWidget(centralWidget); setCentralWidget(centralWidget);Someone have any idea? How can i divide the central widget in two equal part, one for the plot and the other for the leds?


