Greetings all,
so, about two years ago i was plagued by an inability to repaint an instance of TQtWidget from within a QApplication. here is the link to the topic.
the project i was working on has evolved a bit since then and we have recently decided to rework a large portion of it. now, we will have several root plots embedded within a QT GUI. to assist in managing these plots they are all derived from a base class i called RootPlot.
here’s the header
#define ROOTPLOT_H
#include <QtGui/QWidget>
#include <TQtWidget.h>
#include <QWidget>
#include <QSize>
#include <TGraph.h>
class RootPlot : public TQtWidget
{
Q_OBJECT
public:
RootPlot(QWidget *parent = 0);
void show(bool s=1);
private:
virtual void Draw();
virtual void ClearCanvas();
bool _toggle;
TGraph* DefaultPlot;
private slots:
virtual void UpdateCanvas();
virtual void Initialize();
};
#endif // ROOTPLOT_H
and the source
#include <RootPlot.h>
#include <math.h>
#include <TCanvas.h>
#include <TVector3.h>
#include <TROOT.h>
#include <TStyle.h>
#include <TIterator.h>
#include <TGraph.h>
#include <iostream>
RootPlot::RootPlot(QWidget *parent)
{
this->GetCanvas()->cd();
this->GetCanvas()->SetFillColor(0);
_toggle=0;
Int_t n = 20;
Double_t x[n], y[n];
for (Int_t i=0; i<n; i++) {
x[i] = i*0.1;
y[i] = 10*sin(x[i]+0.2);
}
DefaultPlot = new TGraph(n, x, y);
DefaultPlot->SetTitle("mygraph");
DefaultPlot->Draw("AC*");
Draw();
//this->GetCanvas()->Show();
//updateGeometry();
}
void RootPlot::UpdateCanvas()
{
std::cout<<"i'm in ur canvas, updatin ur stuff!"<<std::endl;
_toggle = !_toggle;
Draw();
}
void RootPlot::Initialize()
{
}
void RootPlot::Draw()
{
if (_toggle)
{
Int_t n = 20;
Double_t x[n], y[n];
for (Int_t i=0; i<n; i++)
{
x[i] = i*0.1;
y[i] = 10*sin(x[i]+0.2);
DefaultPlot->SetPoint(i,x[i],y[i]);
}
}
else
{
Int_t n = 20;
Double_t x[n], y[n];
for (Int_t i=0; i<n; i++)
{
x[i] = i*0.1;
y[i] = 10*cos(x[i]+0.2);
DefaultPlot->SetPoint(i,x[i],y[i]);
}
}
DefaultPlot->Draw("AC*");
this->GetCanvas()->Modified();
this->GetCanvas()->Update();
}
void RootPlot::show(bool s)
{
if(s)
{
updateGeometry();
this->show();
}
else
{
updateGeometry();
this->hide();
}
}
void RootPlot::ClearCanvas()
{
this->GetCanvas()->Clear();
this->GetCanvas()->Modified();
this->GetCanvas()->Update();
}
this is the base class for all the embedded plots i will be using in the GUI. on its own, it simply draws one of two TGraphs and toggles between them when UpdateCanvas() is called (the plots are there so i can use the class as a place holder when i need to). this toggeling between two TGraphs works fine and the canvas gets repainted each time.
now, when i create a specific plot, i simply inherit this class, and reimpliment the nescissary functions (like Draw() or UpdateCanvas() ). in these plots i am drawing …
~ an empty TH2D to place axis on the canvas
~ about 3000 circular TMarkers.
i am currently working on a bare bones example that i can upload here without needing to run it by the collaboration board for the project.
i also didnt realize that there were aditional responses from my post two years ago. many of the questions in those responses may apply here, so to answer them…
-
I can’t give specific information about my enviornment variables. the project is being worked on in the most recent version of QTCreator. the OS is Ubuntu 12.04 LTS, i am using ROOT 5.30.01 and compiling with g++ through qmake.
-
the TCanvas / TPad double buffering is not disabled anywhere within the code. if it IS disabled, it has happened internally and without my knowledge.
-
this->Erase() does nothing.
-
the application is a QApplication
thank you for your time! i would appreciate any help i could get on this topic…