Resize TEmbeddedCanvas in other tabs [Edited]

---- Update —
Okay… so the Canvas itself is resized, but not the TPads inside the Canvas… so the problem lies with resizing all the TPads.

I am writing a simple GUI mostly displaying histograms in separate tabs. I am a bit new to this. Things are going well, but I notice that when I resize the main window, only the visible TEmbeddedCanvas is resized properly. See image attached (I expanded the window, and then selected another tab). I presume I need to write a subroutine that handles the resizing of all the other Canvas. I tried all sort of solutions, including fetching the canvas and trying to Update() them, etc… no success. How do I do this? Thanks in advance!


Hi,

Could you tell us the version of ROOT you are using, which OS (Mac OS X I suppose) + version, and which compiler?
And if you have a simple running macro reproducing the problem, that would help us understanding the problem…

Cheers, Bertrand.

Okay… I solved my problem by using a signal / slot to resize the Canvas when a new tab is being selected.
The problem, as far as I can tell, comes from the fact that I have two levels of tabs. In my first implementation, I had a single tab level and everything was working fine… once I added two high-level tabs (“Monitoring”, “Offline” - see picture), that’s when things started to get hairy. Anyway, here is the piece of code that may be relevant. If there was a more straightforward way to do this, I am interested… I wrote the code with Root 5.34 originally, but in order to produce the dictionary to use signal / slot I switched to Root 6.04. Running on El Capitan OS.

	...
  TGHorizontalFrame *mainFrame = new TGHorizontalFrame(this, w, h);
  TGTab *tab = new TGTab(mainFrame, 1, 1);
  
  TGCompositeFrame *moniFrame = new TGCompositeFrame();
  moniFrame = tab->AddTab("Monitoring data");
  // MY FIX HERE (needed to handle resizing when switching high-level tab) ----
  tab->Connect("Selected(Int_t)", "EventDisplay", this, "DoTab(Int_t)");
  // ------------
  monitab = new TGTab(moniFrame,1,1);
  moniFrame->AddFrame(monitab,hint_plots); 
  // MY FIX HERE (needed to handle resizing within the "monitoring" tab) ----
  monitab->Connect("Selected(Int_t)", "EventDisplay", this, "DoTabMoni(Int_t)");
  // --------------------
  TGCompositeFrame *moni_hTab[moni_nH];
  for (int i=0;i<moni_nH;i++) {
    moni_hTab[i] = monitab->AddTab(moni_histoname[i]);
    moni_Canvas[i] = new TRootEmbeddedCanvas(moni_histoname[i], moni_hTab[i], w, h);
    moni_hTab[i]->AddFrame(moni_Canvas[i], hint);
    }
 
  TGCompositeFrame *offlineFrame = new TGCompositeFrame();
  offlineFrame = tab->AddTab("Offline data");
  offlinetab = new TGTab(offlineFrame,1,1);
  offlineFrame->AddFrame(offlinetab,hint_plots);
  // MY FIX HERE (needed to handle resizing within the "offline" tab) ----
  offlinetab->Connect("Selected(Int_t)", "EventDisplay", this, "DoTabOffline(Int_t)");
  // --------------------
  TGCompositeFrame *offline_hTab[offline_nH];
  for (int i=0;i<offline_nH;i++) {
    offline_hTab[i] = offlinetab->AddTab(offline_histoname[i]);
    offline_Canvas[i] = new TRootEmbeddedCanvas(offline_histoname[i], offline_hTab[i], w, h);
    offline_hTab[i]->AddFrame(offline_Canvas[i], hint);
  }
  
  tab->Resize(tab->GetDefaultSize());
  mainFrame->AddFrame(tab, hint);
  
  AddFrame(mainFrame, hint);
  
  	...

Hi,

I cannot test on MacOS, but could you try this (based on what you posted) and let me know if it works for you?

[code]#include “TGFrame.h”
#include “TGTab.h”
#include “TRootEmbeddedCanvas.h”
#include “TCanvas.h”
#include “TH1F.h”

void fsarazin()
{
const char *moni_histoname[] = {“moni_1”,“moni_2”,“moni_3”,“moni_4”,“moni_5”,0};
const char *offline_histoname[] = {“off_1”,“off_2”,“off_3”,“off_4”,“off_5”,0};

TGLayoutHints *hint = new TGLayoutHints(kLHintsExpandX|kLHintsExpandY,2,2,2,2);
TGLayoutHints *hint_plots = hint;

// main frame
TGMainFrame *mainFrame = new TGMainFrame(gClient->GetRoot(),500, 300);

TGTab *tab = new TGTab(mainFrame, 1, 1);

TGCompositeFrame *moniFrame = tab->AddTab(“Monitoring data”);

TGTab *monitab = new TGTab(moniFrame,1,1);
moniFrame->AddFrame(monitab,hint_plots);

TGCompositeFrame *moni_hTab[5];
TRootEmbeddedCanvas *moni_Canvas[5];
for (int i=0;i<5;i++) {
moni_hTab[i] = monitab->AddTab(moni_histoname[i]);
moni_Canvas[i] = new TRootEmbeddedCanvas(moni_histoname[i], moni_hTab[i], 500, 300);
moni_hTab[i]->AddFrame(moni_Canvas[i], hint);
}

TGCompositeFrame *offlineFrame = tab->AddTab(“Offline data”);
TGTab *offlinetab = new TGTab(offlineFrame,1,1);
offlineFrame->AddFrame(offlinetab,hint_plots);

TGCompositeFrame *offline_hTab[5];
TRootEmbeddedCanvas *offline_Canvas[5];
for (int i=0;i<5;i++) {
offline_hTab[i] = offlinetab->AddTab(offline_histoname[i]);
offline_Canvas[i] = new TRootEmbeddedCanvas(offline_histoname[i], offline_hTab[i], 500, 300);
offline_hTab[i]->AddFrame(offline_Canvas[i], hint);
}

tab->Resize(tab->GetDefaultSize());
mainFrame->AddFrame(tab, hint);

TH1F *m_h[5];
for (int i=0;i<5;i++) {
m_h[i] = new TH1F(moni_histoname[i], moni_histoname[i], 100, -5, 5);
m_h[i]->FillRandom(“gaus”,15000);
m_h[i]->SetFillColor(i+2);
m_h[i]->SetFillStyle(3004);
moni_Canvas[i]->GetCanvas()->cd();
m_h[i]->Draw();
moni_Canvas[i]->GetCanvas()->Update();
}

TH1F *o_h[5];
for (int i=0;i<5;i++) {
o_h[i] = new TH1F(offline_histoname[i], offline_histoname[i], 100, 0, 50);
o_h[i]->FillRandom(“landau”,15000);
o_h[i]->SetFillColor(i+2);
o_h[i]->SetFillStyle(3004);
offline_Canvas[i]->GetCanvas()->cd();
o_h[i]->Draw();
offline_Canvas[i]->GetCanvas()->Update();
}

mainFrame->MapSubwindows();

mainFrame->Resize(mainFrame->GetDefaultSize());
mainFrame->MapWindow();
mainFrame->Resize(900,600);
}
[/code]
Cheers, Bertrand.

Bertrand,
similar issue as far as I can tell. The MainFrame resize at the end had a weird effect. See some pictures attached. Starting from Monitoring - moni_1 which looks fine, moni_2, moni_3, moni_4, moni_5 did not resize. Going to Offline - off_1 did not resize, but off_2, off_3, off_4 and off_5 did! More weirdness, when I resize an offline window, none of my other offline plots resize, but moni_2, moni_3, moni_4, moni_5 did, not moni_1 though. I didn’t look further to see what is going on.

As mentioned in my previous post, I did manage to fix the problem by using a signal / slot. Are you suspecting
a bug of some sort with the mac version? I ran your script with 5.34 and 6.0X.






Hi,

[quote=“fsarazin”]As mentioned in my previous post, I did manage to fix the problem by using a signal / slot. Are you suspecting
a bug of some sort with the mac version? I ran your script with 5.34 and 6.0X.[/quote]
Yes, this is a mac issue (with the native - cocoa - implementation only). I’ll forward the problem to the original author of TGCocoa, and we’ll see if he knows how to fix this. At least you found a workaround… :slight_smile:

Cheers, Bertrand.