Cannot display toolbar

Hello,

I have a TRootEmbeddedCanvas in my GUI and would like to toggle/display the toolbar in the canvas just like it is done in TBrowser. However, I cannot get the toolbar to display. It will toggle but it doesn’t show up. Here is an example of the issue. I thought that by toggling the toolbar, it should display, but I must be mistaken. Any insight is greatly appreciated or if clarification is needed, please let me know. Thanks!
canvasError.C (1.95 KB)

Hi,

The toolbar (and the status bar) can only displayed in the TCanvas (TRootCanvas), and are not available in the TRootEmbeddedCanvas.

Cheers, Bertrand.

Hi Bertrand,

OK, thank you. So just to be sure I understand, even though I use GetCanvas() to get the TCanvas variable in my embedded canvas, it still will not work?

Hi,

No, as I said, the toolbar (and the status bar) are only available in TRootCanvas, which is a TGMainFrame, into which they are displayed. If you want the same, you have to display them yourself (just look into the TRootCanvas class how it is done)

Cheers, Bertrand.

Hi Again,

Note that you can also embed a TRootCanvas in a TGCompositeFrame, like for example:

[code]#include “TGFrame.h”
#include “TCanvas.h”

void test_embedded_canvas()
{
TGMainFrame* mf = new TGMainFrame(gClient->GetRoot(), 800, 400);
mf->SetWindowName(“Foo”);

TGHorizontalFrame *evf = new TGHorizontalFrame(mf, 400, 400);
mf->AddFrame(evf, new TGLayoutHints(kLHintsExpandX | kLHintsExpandY,
20, 20, 20, 20));
mf->MapSubwindows();
mf->Layout();

// this is where embedding is done:
evf->SetEditable();
TCanvas* c = new TCanvas(“Foo”, “Bar”, 400, 400);
evf->SetEditable(kFALSE);

mf->Layout();
mf->MapWindow();
}
[/code]Then the toolbar can be displayed (but the menu will be displayed as well)

Cheers, Bertrand.

Hi Bertrand,

Thank you very much for the clarification and the example. I really appreciate it. I’ll have to think if I can transition over to TRootCanvas or just make the toolbar myself.

Thanks again!

Hi Bertrand,

I’ve decided to work on embedding a TCanvas canvas and had a couple questions.

  1. When I run the macro, the toolbar shows up fine when I click on it. For the status bar, I click to display it for the first time and then need to manually resize the window to make the status bar appear. Is there something I can do to remedy that? After the first time, it automatically appears whenever I click it.

  2. When I click on Editor, it doesn’t show up. Is there something additional I need to do?

Thank you!

Hi,

Take a look at your modified example:

[code]#include <TGClient.h>
#include <TCanvas.h>
#include <TF1.h>
#include <TRandom.h>
#include <TGButton.h>
#include <TGFrame.h>
#include <TRootEmbeddedCanvas.h>

class MyMainFrame : public TGMainFrame {
private:
TCanvas *fCanvas;
public:
MyMainFrame(const TGWindow *p,UInt_t w,UInt_t h);
virtual ~MyMainFrame();
void ToggleToolbar();
void ToggleStatusbar();
};

MyMainFrame::MyMainFrame(const TGWindow *p,UInt_t w,UInt_t h) :
TGMainFrame(p,w,h)
{
// this is where the actual embedding is done
SetEditable();
fCanvas = new TCanvas(“Foo”, “Bar”, w, h);
SetEditable(kFALSE);
TRootCanvas *rc = (TRootCanvas *)fCanvas->GetCanvasImp();

// remove (hide) the menu bar
TGFrameElement *el = 0;
TIter next(rc->GetList());
while ((el = (TGFrameElement *)next())) {
if (el->fFrame->InheritsFrom(“TGMenuBar”)) {
TGMenuBar *mb = (TGMenuBar *)el->fFrame;
TGCompositeFrame *cf = (TGCompositeFrame *) mb->GetParent();
if (cf) cf->HideFrame(mb);
break;
}
}

// Create a horizontal frame widget with buttons
TGHorizontalFrame *hframe = new TGHorizontalFrame(this,200,40);
TGTextButton *toolbar = new TGTextButton(hframe,"&ToolBar");
toolbar->Connect(“Clicked()”,“MyMainFrame”,this,“ToggleToolbar()”);
hframe->AddFrame(toolbar, new TGLayoutHints(kLHintsCenterX, 5,5,3,4));
TGTextButton *statusbar = new TGTextButton(hframe,"&StatusBar");
statusbar->Connect(“Clicked()”,“MyMainFrame”,this,“ToggleStatusbar()”);
hframe->AddFrame(statusbar, new TGLayoutHints(kLHintsCenterX, 5,5,3,4));
AddFrame(hframe, new TGLayoutHints(kLHintsCenterX, 2,2,2,2));

// Set a name to the main frame
SetWindowName(“Simple Example”);

// Map all subwindows of main frame
hframe->MapSubwindows();
hframe->MapWindow();
Layout();

// Initialize the layout algorithm
Resize(GetDefaultSize());

// Map main frame
MapWindow();
}

void MyMainFrame::ToggleToolbar() {
// Toggles the toolbar
fCanvas->ToggleToolBar();
Layout();
cout << "Tool bar: " << fCanvas->GetShowToolBar() << endl;
}

void MyMainFrame::ToggleStatusbar() {
// Toggles the toolbar
fCanvas->ToggleEventStatus();
Layout();
cout << "Status bar: " << fCanvas->GetShowEventStatus() << endl;
}

MyMainFrame::~MyMainFrame() {
// Clean up used widgets: frames, buttons, layout hints
Cleanup();
}

void canvasError() {
// Popup the GUI…
new MyMainFrame(gClient->GetRoot(),600,400);
}
[/code]

Cheers, Bertrand.

Hi Bertrand,

Thank you so much for that example. I’m working on implementing it and for some reason, the file menu bar is not disappearing for me. I’ve posted my code section below. I’ll try to write a macro that duplicates the problem, but the macros so far work (ie make the file menu disappear). :frowning:

[code] TGHorizontalFrame* hevf = new TGHorizontalFrame(hCanvas, 500, 400);
hevf->SetEditable();
fEnergyCanvas = new TCanvas(“Energy Histogram”, “EHist”, 450, 400);
hevf->SetEditable(0);
TRootCanvas *rc = (TRootCanvas *)fEnergyCanvas->GetCanvasImp();

// remove (hide) the menu bar
TGFrameElement *el = 0;
TIter next(rc->GetList());
while ((el = (TGFrameElement *)next())) {
if (el->fFrame->InheritsFrom(“TGMenuBar”)) {
TGMenuBar *mb = (TGMenuBar *)el->fFrame;
TGCompositeFrame *cf = (TGCompositeFrame *) mb->GetParent();
if (cf) cf->HideFrame(mb);
break;
}
}

hCanvas->AddFrame(hevf, new TGLayoutHints(kLHintsRight | kLHintsTop, 2, 2, 2, 2));[/code]

Am I missing mapping or layout commands perhaps?

Hi,

Don’t call MapSubwindows on any frame containing your canvas, otherwise all the subframes will be shown (including the menubar)…

Cheers, Bertrand.

Ah, OK. Thank you. That fixed it.

I do have a couple other questions, but I’ll start a new thread since it’s about something different. Thank you for all your help!

Hi,
I have a similar problem and that is, that I dont know how to hide the menu toolbar. I am using the TCanvas as a giant frame to draw histograms. How can I disable the menu toolbar?

Hi,

[quote=“Mostarba”]Hi,
I have a similar problem and that is, that I dont know how to hide the menu toolbar. I am using the TCanvas as a giant frame to draw histograms. How can I disable the menu toolbar?[/quote]
You mean the menu bar or the toolbar? (they are two different things…)

Cheers, Bertrand.

yeah it is the menu bar I am talking about.
Is there a way to hide it?

thanks very much