[QtRoot] Problem rendering a canvas on Qt widgets

Hi,
Issue resolved. The patch really works! It was my mistake that I had a line like
gPad->RedrawAxis();
after the plotting of the stack (I had added this while searching this forum for various workarounds).
Thank you Valeri once again!
Regards,
Samuel

[quote=“samcy”]Hi, …
Issue resolved. The patch really works …[/quote] =D> I would like to hear from kame to confirm that his issue was resolved as well [-o< .

Hi,
I am sorry that I had missed your post.
Now it works perfectly!
Thank you very much !! :smiley:
Will your patch for TPad be included in the next ROOT release?

[quote=“kame”]… Now it works perfectly! … [/quote] :smiley:
I’ll submit the correction shortly.

By the way, plotting a 2D histogram seems a little slow.
It takes about 1 sec on my PC (core i7 950 + GeForce GTX 460).

Hi Thank you for your report.
Ill be happy to investigate this issue.
I would like to call your attention to the fact the there is the dedicated QtRoot project on SourceForge
sourceforge.net/projects/qtroot/ now.

With the bunch of tools to get the support:
sourceforge.net/projects/qtroot/support
sourceforge.net/tracker/?group_i … id=1252274

I would appreciate if you could file your observation via SourfeForge to follow up.

Hi,

thank you for your guidance.

I posted a message about the performance issue on the SourceForge page.
I would appreciate it if you could take a look at it.

Hi,

I am sorry to bother you, but another problem cropped up.
A pad does not get transparent, i.e., TPad::SetFillStyle(4000) does not work.
I suspect that [url=https://root-forum.cern.ch/t/qtroot-problem-rendering-a-canvas-on-qt-widgets/13085/1 patch for TPad[/url] is related to this phenomenon.

[quote=“kame”]Hi,

I am sorry to bother you, but another problem cropped up.
A pad does not get transparent, i.e., TPad::SetFillStyle(4000) does not work.
I suspect that [url=https://root-forum.cern.ch/t/qtroot-problem-rendering-a-canvas-on-qt-widgets/13085/1 patch for TPad[/url] is related to this phenomenon.[/quote]
Short working example reproducing the issue may help. Meantime, please, check the topic: [QtRoot] Problem rendering a canvas on Qt widgets . Can you revert the “src/TQtBrush.cxx” correction to see whether it helps?

I can not reproduce your issue. I used the the modified version of the hsum.C macro from qtRoot/qtExamples/macros:

[code]// histograms filled and drawn in a loop
void hsum() {
//
// To see the output of this macro, click begin_html here end_html
// Simple example illustrating how to use the C++ interpreter
// to fill histograms in a loop and show the graphics results
//Author: Rene Brun

TCanvas *c1 = new TCanvas(“c1”,“The HSUM example”,200,10,600,400);
c1->SetGrid();

gBenchmark->Start(“hsum”);

// Create some histograms.
TColor *t = new TColor(253,0.,0.,1.,“bluet”,0.2);
gStyle->SetStatColor(253);
TColor *t = new TColor(254,0.,0.,0.,“grayt”,0.2);
gStyle->SetStatTextColor(254);
total = new TH1F(“total”,“This is the total distribution”,100,-4,4);
main = new TH1F(“main”,“Main contributor”,100,-4,4);
s1 = new TH1F(“s1”,“This is the first signal”,100,-4,4);
s2 = new TH1F(“s2”,“This is the second signal”,100,-4,4);
total->Sumw2(); // store the sum of squares of weights
total->SetMarkerStyle(21);
total->SetMarkerSize(0.7);
total->SetFillStyle(4050);
main->SetFillStyle(4050);
main->SetFillColor(16);
s1->SetFillColor(42);
s2->SetFillStyle(4050);
s2->SetFillColor(46);
TSlider *slider = 0;

// Fill histograms randomly
gRandom->SetSeed();
const Int_t kUPDATE = 500;
Float_t xs1, xs2, xmain;
for ( Int_t i=0; i<10000; i++) {
xmain = gRandom->Gaus(-1,1.5);
xs1 = gRandom->Gaus(-0.5,0.5);
xs2 = gRandom->Landau(1,0.15);
main->Fill(xmain);
s1->Fill(xs1,0.3);
s2->Fill(xs2,0.2);
total->Fill(xmain);
total->Fill(xs1,0.3);
total->Fill(xs2,0.2);
if (i && (i%kUPDATE) == 0) {
if (i == kUPDATE) {
total->Draw(“e1p”);
main->Draw(“same”);
s1->Draw(“same”);
s2->Draw(“same”);
c1->Update();
slider = new TSlider(“slider”,
“test”,4.2,0,4.6,total->GetMaximum(),38);
slider->SetFillColor(46);
}
if (slider) slider->SetRange(0,Float_t(i)/10000.);
c1->Modified();
c1->Update();
}
}
slider->SetRange(0,1);
// total->Draw(“sameaxis”); // to redraw axis hidden by the fill area
TLegend *leg = new TLegend(0.1,0.7,0.48,0.9);
leg->SetFillStyle(4000);
leg->SetHeader(“The Legend Title”);
leg->AddEntry(total);
leg->AddEntry(main);
leg->AddEntry(s1);
leg->AddEntry(s2);
leg->Draw();
c1->Modified();
gBenchmark->Show(“hsum”);
cout << “Create the clickable TCanvas HTML image map:” << endl;
c1->Update();
TQtCanvas2Html WebSite(c1,1.8,“html”);
}[/code]and got the correct result:

Hi,

I am sorry. I made a quick and wrong judgement. The pad does get transparent.
It seems due to wrong settings in my rootlogon.C.

BTW, I attached an example program to demonstrate (poor) performance of 2D plotting.
I would appreciate it if you could give it a try.
Should I start another thread for this?
test3.tar (10 KB)

[quote=“kame”]… I am sorry. I … The pad does get transparent. [/quote] =D>

[quote=“kame”]…Should I start another thread for this?[/quote]Yes, you should.[quote=“kame”]I posted a message about the performance issue on the SourceForge page.[/quote]I did not get any ticket via SourceForge viewtopic.php?f=3&t=13426&p=58920#p58798. Please check again.

Some other people that use the TQtWidget in their applications might find it useful to know a workaround for buggy rendering in ROOT v5-30. The solution is to force the fill style and color in the TCanvas of TQtWidget. For example:

TQtWidget* mywidget = ...;
mywidget->GetCanvas()->SetFillStyle(4100);
mywidget->GetCanvas()->SetFillColor(10);

For whatever reason styles 1001 or color 0 does not work.

i Artur,
Thank you very much for your report. Thanks this bug I got an opportunity to learn that QtRoot is used (in South Africa. :unamused: Wow ).

However, … I was not able to reproduce your #-o problem with my HelloCanvas.cxx example.

[code]/****************************************************************
**
** Minimal ROOT based Qt example
**
****************************************************************/
#include <qapplication.h>

#include “TGraph.h”
#include “TQtWidget.h”
#include “TCanvas.h”
#include “TDatime.h”
#include “TAxis.h”
#include
int main( int argc, char **argv )
{

QApplication *app = new QApplication(argc, argv);
app->connect(app,SIGNAL(lastWindowClosed ()),app,SLOT(quit()));

TQtWidget *MyWidget= new TQtWidget(0,"MyWidget");
MyWidget->resize(300,200);

// Add some tool tip:
MyWidget->setToolTip("Close this widget to terminate your application");

// Create any other Qt-widget here
//         . . .

// Make the the embedded TCanvas to be the current ROOT TCanvas
MyWidget->GetCanvas()->cd();
gPad->SetFillColor(3);


TDatime datTime (2009,3,4,17,2,0);
double timeOffset = (double) datTime.Convert();

float x[] = {1,2,3,4,5};
float y[] = {1.5f, 3.0f, 4.5f, 3.8f,5.2f};
TGraph*  m_graph  = new TGraph(sizeof(x)/sizeof(float),x,y);

m_graph->GetXaxis()->SetLabelOffset(0.04f);
m_graph->GetXaxis()->SetLabelSize(0.02f);
m_graph->GetXaxis()->SetTimeDisplay(1);
m_graph->GetXaxis()->SetTimeOffset(timeOffset, "local");
char timeFormat[] = "#splitline{%d\\/%b\\/%Y}{%H:%M:%S}";
m_graph->GetXaxis()->SetTimeFormat(timeFormat);
m_graph->GetYaxis()->SetLabelSize(0.04f);
m_graph->SetTitle("Just a test");

m_graph->SetMarkerStyle(7);
m_graph->Draw("AC*");


//Add Qt QLabel onto the top the ROOT TCanvas
QLabel *label = new QLabel("<b>HelloCanvas</b> Example",MyWidget);
label->setStyleSheet("border: 2px solid blue; border-radius: 10px; padding: 0 8px;");
label->move(40,40);
label->resize(148,26);
label->setToolTip("This is a QLabel object");

// Raise the widget on the top
MyWidget->show();
MyWidget->Refresh();

// Create the png file
MyWidget->Save("HelloCanvas.png");
app->exec();
printf(" Good bye, ROOT Canvas\n");
return 0;

}[/code]

Hi everybody,

I’ve just registered to report the same “bug”, both in ROOT 5.30 and 5.32, with Qt4 under Ubuntu 11.04; I found this topic so I add my story here instead of opening a new one… basically, I use Qt to monitor an acquisition system, and a TQtWidget for displaying signal waveforms using histograms; the code that worked with ROOT 5.28 causes the histograms to overlap with newer versions - the same effect discussed in [QtRoot] Canvas update problem. Actually, there was only one histogram in the canvas, that I could move and manipulate, but every change I made was somehow “impressed” in the background.

The solution provided by artur worked for me, and now my “oscilloscope” is up and running… thanks! =D>

(By the way, I had to upgrade ROOT from 5.28 due to repeated “segmentation violation” related to TQtWidget… but this now belongs to the past!)

[quote=“davide84”]… I’ve just registered to report the same “bug”, both in ROOT 5.30 and 5.32, with Qt4 under Ubuntu 11.04; I found this topic so I add my story here instead of opening a new one… basically, I use Qt to monitor an acquisition system, and a TQtWidget for displaying signal waveforms using histograms; the code that worked with ROOT 5.28 causes the histograms to overlap with newer versions -[/quote]I would suggest to communciate the issue via savannah.cern.ch/bugs/?80560
Since the corrections should be done “outside” of “QtRoot domain” I cannot introduce it myself.
I believe the corrections may improve the performance of the X11 /Win32 ROOT favour also by eliminating the redundant rendering.[quote=“davide84”]
… my “oscilloscope” is up and running… thanks! =D>
[/quote] :smiley:
Can you show me your “oscilloscope” or mention it on viewforum.php?f=12 #-o

[quote=“davide84”]
(By the way, I had to upgrade ROOT from 5.28 due to repeated “segmentation violation” related to TQtWidget… but this now belongs to the past!)[/quote] It is a pity, you should not ](*,) keep this as a secret

I’ll try to do all the things you asked me for… :wink: let’s start from the segm.viol. (I’m not sure I want to open a new discussion, I’m not using that version of ROOT anymore…):

[code]machine$./program
** Id: TGQt.cxx 36275 2010-10-11 08:05:21Z brun this=0x10eb3c0

*** Break *** segmentation violation

===========================================================
There was a crash.
This is the entire stack trace of all threads:

#0 0x00007f126bb97f7e in waitpid () from /lib/libc.so.6
#1 0x00007f126bb2f7e9 in ?? () from /lib/libc.so.6
#2 0x00007f1273694b91 in TUnixSystem::StackTrace() ()
from /usr/local/root/lib/libCore.so
#3 0x00007f1273694103 in TUnixSystem::DispatchSignals(ESignals) ()
from /usr/local/root/lib/libCore.so
#4
#5 0x00007f12746069ae in QFont::QFont(QFont const&, QPaintDevice*) ()
from /usr/lib/libQtGui.so.4
#6 0x00007f1274435ec3 in QWidgetPrivate::updateFont(QFont const&) ()
from /usr/lib/libQtGui.so.4
#7 0x00007f1274435dfc in QWidgetPrivate::resolveFont() ()
from /usr/lib/libQtGui.so.4
#8 0x00007f127443c8ec in QWidget::event(QEvent*) ()
from /usr/lib/libQtGui.so.4
#9 0x00007f12743e622c in QApplicationPrivate::notify_helper(QObject*, QEvent*)
() from /usr/lib/libQtGui.so.4
#10 0x00007f12743ec6fb in QApplication::notify(QObject*, QEvent*) ()
from /usr/lib/libQtGui.so.4
#11 0x00007f1273f1306c in QCoreApplication::notifyInternal(QObject*, QEvent*)
() from /usr/lib/libQtCore.so.4
#12 0x00007f12743ea128 in QApplication::setFont(QFont const&, char const*) ()
from /usr/lib/libQtGui.so.4
#13 0x00007f126ef072ec in TGQt::Init(void*) ()
from /usr/local/root/lib/libGQt.so
#14 0x00007f126ef08ceb in TGQt::TGQt(char const*, char const*) ()
from /usr/local/root/lib/libGQt.so
#15 0x00007f126ef26c1f in G__G__GQt_165_0_7(G__value*, char const*, G__param*, int) () from /usr/local/root/lib/libGQt.so
#16 0x00007f1272b4326f in Cint::G__CallFunc::Execute(void*) ()
from /usr/local/root/lib/libCint.so
#17 0x00007f1273650a21 in TCint::CallFunc_ExecInt(void*, void*) const ()
from /usr/local/root/lib/libCore.so
#18 0x00007f127367b3f1 in TMethodCall::Execute(void*, long&) ()
from /usr/local/root/lib/libCore.so
#19 0x00007f12735e3499 in TPluginHandler::ExecPlugin(int, …) ()
from /usr/local/root/lib/libCore.so
#20 0x00007f12735b10ec in TApplication::LoadGraphicsLibs() ()
from /usr/local/root/lib/libCore.so
#21 0x00007f12735b1ddc in TApplication::InitializeGraphics() ()
from /usr/local/root/lib/libCore.so
#22 0x00007f12735b3720 in TApplication::TApplication(char const*, int*, char**, void*, int) () from /usr/local/root/lib/libCore.so
#23 0x00007f1270d05875 in TRint::TRint(char const*, int*, char**, void*, int, bool) () from /usr/local/root/lib/libRint.so
#24 0x00007f126ef1b0b6 in TQtWidget::InitRint(bool, char const*, int*, char**, void*, int, bool) () from /usr/local/root/lib/libGQt.so
#25 0x00007f126ef1b76f in TQtWidget::Init() ()
from /usr/local/root/lib/libGQt.so
#26 0x00007f126ef1bb86 in TQtWidget::TQtWidget(QWidget*, char const*, QFlagsQt::WindowType, bool) () from /usr/local/root/lib/libGQt.so
#27 0x00000000004151ae in aidaGUI::initGUI() ()
#28 0x000000000041705d in aidaGUI::aidaGUI(QApplication*) ()
#29 0x0000000000417854 in main ()

The lines below might hint at the cause of the crash.
If they do not help you then please submit a bug report at
Sign in to GitHub · GitHub. Please post the ENTIRE stack trace
from above as an attachment in addition to anything else
that might help us fixing this issue.

#5 0x00007f12746069ae in QFont::QFont(QFont const&, QPaintDevice*) ()
from /usr/lib/libQtGui.so.4
#6 0x00007f1274435ec3 in QWidgetPrivate::updateFont(QFont const&) ()
from /usr/lib/libQtGui.so.4
#7 0x00007f1274435dfc in QWidgetPrivate::resolveFont() ()
from /usr/lib/libQtGui.so.4
#8 0x00007f127443c8ec in QWidget::event(QEvent*) ()
from /usr/lib/libQtGui.so.4
#9 0x00007f12743e622c in QApplicationPrivate::notify_helper(QObject*, QEvent*)
() from /usr/lib/libQtGui.so.4
#10 0x00007f12743ec6fb in QApplication::notify(QObject*, QEvent*) ()
from /usr/lib/libQtGui.so.4
#11 0x00007f1273f1306c in QCoreApplication::notifyInternal(QObject*, QEvent*)
() from /usr/lib/libQtCore.so.4
#12 0x00007f12743ea128 in QApplication::setFont(QFont const&, char const*) ()
from /usr/lib/libQtGui.so.4
#13 0x00007f126ef072ec in TGQt::Init(void*) ()
from /usr/local/root/lib/libGQt.so
#14 0x00007f126ef08ceb in TGQt::TGQt(char const*, char const*) ()
from /usr/local/root/lib/libGQt.so
===========================================================[/code]

After some debugging, I (think I) identified the problem:

root_canvas = new TQtWidget(this,"canvas");

obviously the object has been previously globally declared as

TQtWidget *root_canvas;

The crash appeared randomly at startup. If I create the object, but not add it to the layouts, the crash persisted; I had to completely eliminate “root_canvas”, or launch my program several times until it works (can be once, can be 5 times…).

With another 64bit machine, the same Ubuntu 11.04, the same Qt4, the same ROOT 5.28, and a similar program that uses a monitor canvas in the same way, I don’t have any problem… I solved with ROOT 5.32.

Thank you for your time.
It looks like the memory corruption, :confused: … somewhere … one needs to reproduce this under gdb … Anyway, I did not remember #-o to change something within the TQtWidget since 5.28.

[quote=“davide84”]I’m not using that version of ROOT anymore…):[/quote] Thank you, I’ll bookmark this topic for my record.

[quote=“fine”][quote=“davide84”]
… my “oscilloscope” is up and running… thanks! =D>
[/quote] :smiley:
Can you show me your “oscilloscope” or mention it on viewforum.php?f=12 #-o[/quote]
Hi, I’m sorry but I still don’t have the time to write something about the visualization, but you can see something in Chapter 3 of my thesis work: spiro.fisica.unipd.it/~cester/docs/tesi_5.pdf our software can work both in “oscilloscope” and in “spectrum” modes.
If you think it can be of interest the way I manage the update or things like that… I can try to open a topic in viewforum.php?f=12.