How do I "split the window"?
-
This post is about same issue I have posted elsewhere, but it is NOT a dupe....
I just need some fresh , different idea how to solve
I have "main window " ( QMainWindow) where
setCentralWidget(m_console);
is my current, final "view" I/O "window" ( plain text class )
and it does the job accessing the serial port....
What I want is to have ANOTHER way to access the serial port - ideally showing BOTH the original console "view" and the new means to access same serial port.
I have replaced the "console" with MDIArea , however it is getting too convoluted to have the original "console" and the
new access as TWO subwindow of the MDIArea....In not so technical description - how do I "split" the current I//O ( console ) "window" and add another "view" of same serial port.
So currently I have
(main) MDI class
real subwindow - QMainWindow ( access to serial ports)
console class as I/Owhat I like to have
(main) MDI class
rear subwindow - QMainWindow ( access to serial ports)intermediate way / class - split final view
original view - console class as I/O
new , additional view - serial control class as I/O//! [0] MainWindow_Serial::MainWindow_Serial(QWidget *parent) : QMainWindow(parent), m_ui(new Ui::MainWindow_Serial), 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); setCentralWidget(m_console); ' ***replaced with QMainWindow -> QMDIArea*** m_ui->actionConnect->setEnabled(true); m_ui->actionDisconnect->setEnabled(false); m_ui->actionQuit->setEnabled(true); m_ui->actionConfigure->setEnabled(true); m_ui->statusBar->addWidget(m_status); initActionsConnections(); connect(m_serial, &QSerialPort::errorOccurred, this, &MainWindow_Serial::handleError); //! [2] connect(m_serial, &QSerialPort::readyRead, this, &MainWindow_Serial::readData); //! [2] connect(m_console, &Console::getData, this, &MainWindow_Serial::writeData); //! [3] }
-
This post is about same issue I have posted elsewhere, but it is NOT a dupe....
I just need some fresh , different idea how to solve
I have "main window " ( QMainWindow) where
setCentralWidget(m_console);
is my current, final "view" I/O "window" ( plain text class )
and it does the job accessing the serial port....
What I want is to have ANOTHER way to access the serial port - ideally showing BOTH the original console "view" and the new means to access same serial port.
I have replaced the "console" with MDIArea , however it is getting too convoluted to have the original "console" and the
new access as TWO subwindow of the MDIArea....In not so technical description - how do I "split" the current I//O ( console ) "window" and add another "view" of same serial port.
So currently I have
(main) MDI class
real subwindow - QMainWindow ( access to serial ports)
console class as I/Owhat I like to have
(main) MDI class
rear subwindow - QMainWindow ( access to serial ports)intermediate way / class - split final view
original view - console class as I/O
new , additional view - serial control class as I/O//! [0] MainWindow_Serial::MainWindow_Serial(QWidget *parent) : QMainWindow(parent), m_ui(new Ui::MainWindow_Serial), 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); setCentralWidget(m_console); ' ***replaced with QMainWindow -> QMDIArea*** m_ui->actionConnect->setEnabled(true); m_ui->actionDisconnect->setEnabled(false); m_ui->actionQuit->setEnabled(true); m_ui->actionConfigure->setEnabled(true); m_ui->statusBar->addWidget(m_status); initActionsConnections(); connect(m_serial, &QSerialPort::errorOccurred, this, &MainWindow_Serial::handleError); //! [2] connect(m_serial, &QSerialPort::readyRead, this, &MainWindow_Serial::readData); //! [2] connect(m_console, &Console::getData, this, &MainWindow_Serial::writeData); //! [3] }
Hi @AnneRanch,
Personally I like to use
QDockWidget
for this. So you can easily move, resize, hide/show your view according to your needs.Something like that
QDockWidget *dock = new QDockWidget(tr("Serial"), this); dock->setAllowedAreas(Qt::LeftDockWidgetArea | Qt::RightDockWidgetArea); m_serialCtrl = SerialControlWidget() dock->setWidget(serialCtrl); this->addDockWidget(Qt::RightDockWidgetArea, dock); // Optional, allow to show/hide view from the menu and/or toolbar viewMenu->addAction(dock->toggleViewAction());
Another possibility would be to use a QSplitter as main widget, and set your two widgets
console
andserial
as "childs".//setCentralWidget(m_console); QSplitter *splitter = new QSplitter(Qt::Horizontal); splitter.addWidget(m_console); splitter.addWidget(m_serialCtr); setCentralWidget(m_serialCtrl);