Multiple QMainCanvas inside QTabWidget lead to overlay

_ROOT Version: 6.27/01
Platform: Windows
Compiler: QT5.15 + MSVC2019

Dear Rooters,
I am using the QMainCanvas and QRootCanvas from that I obtained here Root canvas in Qt5 revisited.
To do so, I have a QTabWidget in my QT application with 4 tabs. In each tab I want to plot a different graph. I have then created in each tab a QWidget promoted to QMainCanvas ( I also tried promoting to QRootCanvas but same result, see below).
When I plot a canvas from one tab, then I go to the next tab and the previous plot still appear like if it is overlaying all the areas where I put a QMainCanvas. If, in the other tab, I generate a new plot, then the new plot appear inside the previous canvas, smaller. As a long explanation might not be so clear, please look at the picture below.

I do not understand this behavior. Everything happens like if the histogram was generated in the 4 canvas while they are different objects and I do not see in the classes from simple_canvas that they are a singleton. Furthermore, when generating a new histogram it appear at the top left of the first one, in small.

Any idea of what could be wrong?
Thanks in advance.

Can you provide a piece of code showing the problem? (and note that Qt and ROOT is not officially supported anymore)

Is it new that QT / root is not supported? I did not know about that. It’s sad because it enriches QT with the possibility to directly use data in the root format. At least that is what I am trying to do :slight_smile:.

The code is the one I found in simple_canvas.
I have a simple QApplication with a QMainWindow in which there is a QTabWidget with 5 tabs and in each one I set a QWidget that I promote in QMainCanvas.

To avoid complex code defining here and not give you additional work, I have produced a minimal example attached: (7.2 KB)

Thanks a lot

So the problem comes when switching tabs. One should react to currentChanged(int index) and refresh the layout (maybe something like in QMainCanvas::changeEvent(QEvent * e)).
I’m looking at it

So I added a QMainCanvas::forceUpdate() method:

void QMainCanvas::forceUpdate()
    if (canvas->getCanvas()) {

And connecting the currentChanged(int) signal to a new tabChanged(int) slot method in the MainWindow ctor:

    connect(ui->tabWidget, SIGNAL(currentChanged(int)), this, SLOT(tabChanged(int)));

doing something like this:

void MainWindow::tabChanged(int)

Fixes the issue. I’ll let you make it cleaner :wink:

1 Like

Thank you very much Bertrand. I do not understand why the canvas needs to be updated each time I change the tab. I thought what is plotted inside the canvas is kept and changing the tab is just changing the focus for another canvas.
Anyway, your solution works and I am thankful for this.

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.