Hi H.-Greg, The solution I found is not elegant but might help for the moment: TFile *f = new TFile ... TCanvas *c = (TCanvas*)f->Get("c1"); Int_t w = c->GetWindowWidth(); Int_t h = c->GetWindowHeight(); TRootEmbeddedCanvas *embed = new TRootEmbeddedCanvas(0, fMain, w, h, kHorizontalFrame); TCanvas* canvas = new TCanvas("Empty", w, h, embed->GetCanvasWindowId()); embed->AdoptCanvas(canvas); fMain->AddFrame(embed, new TGLayoutHints(kLHintsExpandX | kLHintsExpandY)); embed->GetCanvas()->cd(); TObject *obj, *cobj; TIter next(c->GetListOfPrimitives()); while ((obj=next())) { cobj = obj->Clone(); embed->GetCanvas()->GetListOfPrimitives()->Add(cobj,obj->GetDrawOption()); } embed->GetCanvas()->Modified(); embed->GetCanvas()->Update(); Best regards, Ilka p.s. I am receiving the e-mails with a delay of several hours and you could have already an answer... "H.-Gerd Rosarius" wrote: > Hello Rooters, > > currently I'm going to program a small GUI application which > imports a canvas with a histogram on it from a root-file and > displays it on the screen. > > For this purpose I use the following code: > > // --- Code start ---------------------------------------------------- > > // Do stuff like initialising TGMainFrame object etc. > > // Import canvas from root-file > TFile* f = new TFile("/home/xxxxxx/root-files/demo.root"); > TCanvas* c = (TCanvas*) f->Get("c1"); > > // Define a base canvas > TGCanvas* canvas = new TGCanvas( this, 1280, 1024, kHorizontalFrame | > kSunkenFrame); > > // Create embedded canvas and create root-canvas > TRootEmbeddedCanvas* rootCanvas = new TRootEmbeddedCanvas(0, > canvas->GetViewPort(), 800, 400, kHorizontalFrame); > TCanvas* myRootCanvas = new TCanvas("Empty", 800, 400, > rootCanvas->GetCanvasWindowId()); > > // Add imported canvas to empty canvas > myRootCanvas->SetCanvas( c ); > myRootCanvas->cd(); > myRootCanvas->Update(); > > // Adopt canvas and set the container > rootCanvas->AdoptCanvas( myRootCanvas ); > canvas->SetContainer( rootCanvas ); > // --- Code snippet end --------------------------------------------- > > Unfortunately not the imported canvas c is displayed in the application. > The (or an) empty canvas myRootCanvas is displayed instead. > > Maybe it's just a beginners mistake... > > Any hints? > > Grettings > > H.-Gerd > > P. S.: Using Root 3.05 built from source on a Debian Linux box.
This archive was generated by hypermail 2b29 : Thu Jan 01 2004 - 17:50:12 MET