TQtWidget and (default) menubar

Hi fellow Rooters,

In my Root-based Qt application I use a TQtWidget in a Qt popup window. It uses a class with two pointers,

[code]class frmroot : public QWidget {
public:
frmroot(QWidget *parent = 0, const char *name = 0, WFlags fl = 0);
~frmroot();

TQtWidget *rootwidget;
TCanvas *rootcanvas;

protected:
QHBoxLayout *layout;

private:
int h,v; // window size in pixels
int qrecth0,qrectv0; // origin for setGeometry(QRect()) on TQtWidget

// etc…
[/code]

In this class’ constructor I’m doing:

[code]frmroot::frmroot(QWidget *parent, const char *name, WFlags fl)
: QWidget(parent, name, fl)
{
this->h=600; this->v=480;
this->qrecth0=0; this->qrectv0=0;
if(!name) setName(“frmroot”);

layout = new QHBoxLayout(this, 0,0, "layout");
resize(QSize(this->h,this->v).expandedTo(minimumSizeHint()));

// Set resource variable to prevent QtROOT from crashing
gEnv->SetValue("ktidbexplorer.Gui.Backend","qt");
gStyle->SetPalette(1);
rootwidget = new TQtWidget(this,"rootwidget");
rootwidget->cd();
rootcanvas = rootwidget->GetCanvas();
layout->addWidget(rootwidget);
clearWState( WState_Polished );

[/code]

It works well, in the sense that after constructing one such object and invoking a histogram Draw(), it shows it. But I’d like to use TCanvas’ “default” menubar (the one showing up when creating a new TCanvas). I’ve just started looking at guitest.C for hints but didn’t get too far (other than having to create a menubar from scratch, which I’m still struggling).

So: how can I use TCanvas’ menu bar in my TQtWidget?

Thanks in advance for your help!

Hello jbatista,
There is no abstract interface in ROOT for the TCanvas menu bar yet.
There is the interface for the entire TCanvas “main window”, which is the TCanvasImp class root.cern.ch/root/htmldoc/TCanva … escription
You can find the Qt-based implementation of this interface as a part of Qt-extension ROOT plugin from root.bnl.gov/QtRoot/root/qtgui/s … vasImp.cxx
See: TQtCanvasImp::MakeMenu() there

I think there are several ways to achieve what you want.

But … before we will go further, may I ask you why you did subclass TQtWidget? Your comment // Set resource variable to prevent QtROOT from crashing
suggests it is to provide some workaround for some un-reported TQtWidget bug you had faced and opted to not report it.
Can you elaborate a little bit more.
Thank you

Hi Valeri,

Thanks for your help.

Of course. I’m trying to incorporate Root (graphical) objects within a Qt application window (in this case, a window in a MDI application). Therefore, the constructor automatically calls up a TQtWidget which will be used to hold a TCanvas (to draw an histogram).

[quote=“fine”]Your comment // Set resource variable to prevent QtROOT from crashing
suggests it is to provide some workaround for some un-reported TQtWidget bug you had faced and opted to not report it.
Can you elaborate a little bit more.[/quote]

Yes. After your comment I’ve tried to reproduce the previous problems (i.e. my application “ktidbexplorer” crashing) without success. It now works even with the “hack” commented out… :slight_smile: Looks like the possible bug has been corrected in the meantime!

The original idea for the hack came from this link in the QtRoot documentation: root.bnl.gov/QtRoot/How2Install4 … l#turnQtOn

Ok :laughing:

[quote=“jbatista”]
The original idea for the hack came from this link in the QtRoot documentation: root.bnl.gov/QtRoot/How2Install4 … l#turnQtOn[/quote]
Since January 2006 release it is not necessary anymore to customize the ROOT resource file for ROOT-based Qt-application.
For such application, the “native” parameters for Gui.Backend and Gui.Factory means “qt”. See root.cern.ch/viewcvs/qt/src/TQtWidget.cxx Revision 1.20
Please, pay your attention to the revision 1.21 comment also.

Hi again, Valeri.

[quote=“fine”]You can find the Qt-based implmentation of this interface as a part of Qt-extension ROOT plugin from root.bnl.gov/QtRoot/root/qtgui/s … vasImp.cxx
See: TQtCanvasImp::MakeMenu() there.[/quote]

Are there any plans to merge the Qt-extension to the Root default source tree? (I’m guessing that it’s likely not to happen, since it sounds like TQtCanvasImp::MakeMenu() might be surperfluous relative to other already-existing classes in Root…)

Cheers,
jbatista

[quote=“jbatista”]Hi again, Valeri.
Are there any plans to merge the Qt-extension to the Root default source tree?[/quote] I am not against :wink: . I did raise this issue several times. See, for example, ROOT 2005 Workshop, slide 23 from indico.cern.ch/getFile.py/access … Id=a055638 talk
On the other hand what is the advantage :confused: of such merge for the end-user as soon as you can smoothly (I hope :unamused: ) add the extensions to your local ROOT installation :question: You can add the new GUI features :exclamation: to your old and well-tested ROOT version. Something one may not have accomplished as soon as Qt/Root is merged with the mainstream ROOT.

[quote=“jbatista”]
(I’m guessing that it’s likely not to happen, since it sounds like TQtCanvasImp::MakeMenu() might be surperfluous relative to other already-existing classes in Root…)
Cheers,
jbatista[/quote]

Z[quote=“jbatista”] (. . .it sounds like TQtCanvasImp::MakeMenu() might be surperfluous relative to other already-existing classes in Root…)[/quote]
I am afraid I did not understand your requirement yet. If you need the regular TCanvas “main window” with Qt-implementation you may have created just a “new TCanvas” with the “qtgui backend” turned on via “ROOT resource file”. That requires no extra coding on the user side. As soon as you create that “regular” TCanvas Qt-based main window you can have it customized (since what you get is :bulb: the QMainWindow object) using the Qt API (see: doc.trolltech.com/3.3/qmainwindow.html ). For example, to customise the menu you may want to get QMenuBar pointer
doc.trolltech.com/3.3/qmainwindow.html#menuBar.

The QtRoot/qtExamples package (see: root.bnl.gov/QtRoot/README_Hello_Example ) contains the 9. CustomCanvasMenu - the same as "ex1". In addition, it demonstrates how one can customize the automatically generated ROOT Context Menu. to show how one can customize the ROOT “Context Menu”. The same technique can be applied to the main window :bulb: “Menu Bar”. For the further assistance with QtRoot I would encourage you to send your questions via lists.bnl.gov/mailman/listinfo/qt-root-l

Hi Valeri,

This is not so much insistence on my part, but rather a clarification.

The most basic example of what I’m after is something like what is in the Root User’s Guide 5.12, pg.412-413 on the subsection titled “ROOT-based Qt applications”. In this example, “HelloCanvas.cxx”, the TCanvas is drawn without the menubar we’re used to when doing the usual “new TCanvas()” in the ROOT interactive shell.

My problem was then: can we draw the same “standard” menubar in HelloCanvas.cxx, or do we have to code explicitly the contents of the menubar? I’m after a way to run a Qt application which reads ROOT histograms stored as blobs in a database, with the ability to save the histogram being displayed into a local file.

In the meantime, I’ve worked a way to add menu entries into the drop-down context popup menus, but having ROOT draw the menubar would have helped immensely.

[quote=“jbatista”]My problem was then: can we draw the same “standard” menubar in HelloCanvas.cxx, or do we have to code explicitly the contents of the menubar?
[/quote]I am not sure I did understand what you want (may be you can send me a private message with some extra details) . The goal of that example is to show how one can create the TCanvas object embedded into the simplest QWidget. To get the standard TCanvas “look and feel” one needs to create the standard TCanvas, i.e. you should do new TCanvas rather new TQtWidget. Or do nothing, i.e. create neither TQtWidget nor TCanvas. The TObject::Draw method takes care about the standard TCanvas appearance. In other words, to do what you want you should create the regular vanilla ROOT application without any Qt dependency and turn on the Qt-layer with ROOT resources file. However, this way all high level GUI components are created by ROOT Gui supported by Qt backend. In other words, the main window will be the instance of the TGMainFrame and the menu components are the TGMenu object. Do you care ? If you need your main window to be an instance of the QMainWindow rather TGMainFrame then you need to activate another plugin defined by Gui.Factory parameter and provide an extra shared library.The later is a part of the Qt-extension. That you can download and install from root.bnl.gov