1

I'm trying to implement the following layout

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

Between the TabWidget and GLWidget the layout is governed by a QSplitter with horizontal orientation. Another QSplitter with vertical orientation is needed between the previous splitter and QTextEdit widget so that I can choose to hide the textedit.

Currently my implementation is the following (this is the pointer to 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 seems to work correctly, but when I maximize it, the CPU load jumps to 90% and above and the gui interface is slow!

I've found that you can't put a layout inside a QSplitter http://qt-project.org/doc/qt-4.8/qsplitter.html

so I've tried to comment the line glTabSplitterHorizontal->addWidget(ui->tabWidget); and the CPU is not heavy loaded. The problem is that I need that tabWidget!

How can I work around this issue, keeping my layout with splitters?

linello
  • 8,451
  • 18
  • 63
  • 109
  • Is it definitely `QTabWidget`, what happens if you just put a `QLabel` or `QPushButton` in there - do you still get 100% CPU? – cmannett85 Dec 14 '12 at 08:00
  • Seems that rearranging things in this way solves the issue: http://stackoverflow.com/questions/8685005/qt-making-a-splitter-horizontal-and-vertical-at-same-time?rq=1 – linello Dec 14 '12 at 12:15
  • Please write it as an answer and accept it, thanks :) or even flag/close as duplicate or something – Smar Dec 14 '12 at 12:37

1 Answers1

0

I've restructured my code in the following way:

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 suggestion in this answer

Qt - Making a Splitter Horizontal and Vertical at same time

and the CPU now is no more heavy loaded.

Community
  • 1
  • 1
linello
  • 8,451
  • 18
  • 63
  • 109