[QtRoot] Canvas update problem

Hi,

I am developing a Qt application using ROOT as a plotter. I am using QtRoot (BNL version) with ROOT v5.28.00e on Linux/X11 (because current QtRoot does not compile with ROOT v5.30).
One day I encountered a strange phenomenon; The ROOT canvas embedded with a TQtWidget does not repaint a TGraph correctly when TSpline3 is involved.
I attached the simplest program that reproduces the problem.
The graph is recreated and the canvas is updated when the push button is clicked, but the old graphs remain visible.
This does not occur if the TSpline3 object is not drawn nor when the drawing function is called not via the signal/slot mechanism.
The old graphs disappear when the widget is resized.

Any help would be appreciated.
test.tar (20 KB)

[quote=“kame”]I am developing a Qt application using ROOT as a plotter. I am using QtRoot (BNL version) with ROOT v5.28.00e on Linux/X11 (because current QtRoot does not compile with ROOT v5.30)[/quote]Please check the thread:
lists.bnl.gov/pipermail/qt-root … 00536.html

[quote=“kame”]One day I encountered a strange phenomenon; The ROOT canvas embedded with a TQtWidget does not repaint a TGraph correctly when TSpline3 is involved.[/quote]I’ll check your example and come back shortly.
Thank you

Can you upload the Qt “pro” file rather “Makefile”? I can not use your makefile because it assumes your local env.

I’ve changed your example and the problem disappeared:

[code]— test.cc 2011-08-09 11:45:28.000000000 +0200
+++ test.cc.new 2011-08-17 21:21:12.000000000 +0200
@@ -6,19 +6,20 @@
#include “TSpline.h”
#include “TRandom.h”

-MainWindow::MainWindow(): g(0), s(0)
+MainWindow::MainWindow(): w(0), g(0), s(0)
{
w = new TQtWidget(this);
setCentralWidget(w);

QPushButton *button = new QPushButton(this);
button->setText(“Plot graph”);

  • setMenuWidget(button);
    connect(button, SIGNAL(clicked()), SLOT(PlotGraph()));
    }

void MainWindow::PlotGraph()
{

  • w->GetCanvas()->cd();
  • w->cd();

    delete g;
    g = new TGraph(10);
    @@ -32,9 +33,8 @@
    s->SetLineColor(kRed);
    s->SetLineWidth(2);
    s->Draw(“same”);

  • w->GetCanvas()->Modified();
  • w->GetCanvas()->Update();

Hi, thank you very much for detailed instruction.
Thank you also for the information to compile QtRoot with ROOT v5.30.

Unfortunatelly, the problem does not disapper in my system. The deleted graphs are still displayed. I compiled the program with ROOT v5.30.01.
I attached again my sources modified as you suggested. (Sorry for attaching Makefile instead of *.pro file before.)

Thank you for pointing that out. Now the code is safe because I added TObject::SetBit(kCanDelete, kFALSE), right?
test2.tar (10 KB)

  • I have not been able to reproduce your issue yet, Sorry.
  • Can you check another thread; TGraph updates only on mouse click ?
    Can you try to use TPad::Clear rather “delete s ; delete g” to see whether your problem persists.

Thank you for your quick reply.

I added w->GetCanvas()->Clear(); or w->GetCanvas()->GetPad(0)->Clear(); before drawing, but the canvas is not cleared. (Actually I had tried this before posting.)
Let me confirm again; in your environment, is the canvas correctly updated when the button is clicked two or more times in a row?
By the way, I am using Qt 4.7.3. Are you too?

Does it look like savannah.cern.ch/bugs/index.php?80560 ?

Please, try #-o the patch. ( It may have helped if you could upload the screenshot eliminating the guess job )

[code]diff -uwb test.hold test.cc
— test.hold 2011-08-22 04:15:26.000000000 +0200
+++ test.cc 2011-08-22 04:32:59.000000000 +0200
@@ -15,6 +15,7 @@
button->setText(“Plot graph”);
setMenuWidget(button);
connect(button, SIGNAL(clicked()), SLOT(PlotGraph()));

  • connect(button, SIGNAL(clicked()), w, SLOT(Refresh()));
    }

void MainWindow::PlotGraph()
@@ -25,22 +26,19 @@
delete g;
g = new TGraph(10);
g->SetBit(kCanDelete, kFALSE);

  • g->SetMarkerStyle(2);
    for (int i = 0; i < 10; ++i)
    g->SetPoint(i, i, gRandom->Gaus());

  • g->Draw(“ap”);

    delete s;
    s = new TSpline3("", g);
    s->SetBit(kCanDelete, kFALSE);
    s->SetLineColor(kRed);

  • s->SetMarkerStyle(kStar);
    s->SetLineWidth(2);
  • s->Draw(“same”);
  • s->Draw(“LP”);

    // w->GetCanvas()->Modified();
    // w->GetCanvas()->Update();

  • w->Refresh();
  • update();
    }

int main(int argc, char *argv[])[/code]

Hi, thank you for reply.

[quote=“fine”]Does it look like savannah.cern.ch/bugs/index.php?80560 ?[/quote]It looks like a similar phenomenon.

[quote=“fine”]Please, try #-o the patch. [/quote]The problem disappeard after I applied this patch !
I can proceed with my project :smiley:. Thanks a lot!

For your reference, I attached a screenshot of the program window before patching when the push button is clicked three times.

I updated ROOT to v5.34.03, then above solution seems no longer effective.
That is, disabling GetPainter()->SetFillStyle(0) in TPad::PaintBox(…) method (see blow) does not fix the problem any more.

void TPad::PaintBox(Double_t x1, Double_t y1, Double_t x2, Double_t y2, Option_t *option)
{
   // Paint box in CurrentPad World coordinates.
   //
   // if option[0] = 's' the box is forced to be paint with style=0
   // if option[0] = 'l' the box contour is drawn

   if (!gPad->IsBatch()) {
      Int_t style0 = GetPainter()->GetFillStyle();
      Int_t style  = style0;
      if (option[0] == 's') {
         GetPainter()->SetFillStyle(0);
         style = 0;
      }
      if (style) {
         ....

Hi
Thank you for your report.

Well since the fix was not accepted ( savannah.cern.ch/bugs/index.php?80560 ) someone might have done the same thing elsewhere. Just an extra job (and time) to find it.

Sorry, I have no solution to address your last issue. However, the report savannah.cern.ch/bugs/?99855 indicates that we may be facing some new " FillStyle/FillColor" issue to be investigated indeed