Qt QSplitter and a non-responsive graphical interface (cpu 100%)

I am trying to implement the following layout

|~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~| | | | | | | | QTABWIDGET | QGLWIDGET | | | | | | | |_______________|________________| | | | | | TEXTEDIT | |________________________________| 

Between TabWidget and GLWidget, the layout is controlled by a horizontal orientation QSplitter. It requires another QSplitter with a vertical orientation between the previous splitter and the QTextEdit widgets so that I can hide the textedit.

Currently my implementation is as follows ( this is a pointer to the MainWindow class):

 QVBoxLayout *mainWindowLayout = new QVBoxLayout(ui->centralWidget); // Here we setup an horizontal splitter between the TabWidget and the QGLWidget QSplitter *glTabSplitterHorizontal = new QSplitter(Qt::Horizontal,this); glTabSplitterHorizontal->addWidget(ui->tabWidget); // seems to produce the high CPU load glTabSplitterHorizontal->addWidget(this->glWidget); // add the horizontal splitter as first row of the layout QSplitter *splitterConsoleVertical = new QSplitter(Qt::Vertical,this); splitterConsoleVertical->setOrientation(Qt::Vertical); // as first row it must be the previously allocated horizontal layout tabWidget splitterConsoleVertical->addWidget(glTabSplitterHorizontal); mainWindowLayout->addWidget(glTabSplitterHorizontal); 

My application works correctly, but when I maximize it, the CPU utilization reaches 90% and higher, and the gui interface is slow!

I found that you cannot put the layout inside QSplitter http://qt-project.org/doc/qt-4.8/qsplitter.html

so I tried to comment out the line glTabSplitterHorizontal->addWidget(ui->tabWidget); , but the CPU is not loaded. The problem is that I need this tabWidget!

How can I get around this problem by keeping my separator layout?

+1
source share
1 answer

I changed my code as follows:

 QSplitter *splitHorizontal = new QSplitter; QSplitter *splitVertical = new QSplitter; QVBoxLayout *layout = new QVBoxLayout; QWidget *container = new QWidget; QVBoxLayout *container_layout = new QVBoxLayout; splitHorizontal->addWidget(ui->tabWidget); splitHorizontal->addWidget(this->glWidget); container_layout->addWidget(splitHorizontal); container->setLayout(container_layout); splitVertical->setOrientation(Qt::Vertical); splitVertical->addWidget(container); splitVertical->addWidget(new QTextEdit()); layout->addWidget(splitVertical); this->centralWidget()->setLayout(layout); this->centralWidget()->show(); 

following the sentence in this answer

Qt - Creating a horizontal and vertical splitter at the same time

and now the processor is no longer loaded.

0
source

All Articles