Root canvas in Qt5 revisited

I have looked online and in this forum. I have inherited an MFC application that embeds Root (version 5.34/36) to use the TCanvas and am researching the viability of moving from MFC to Qt5 (which is what my company currently uses). The first step of course is to make sure that Qt5 plays well with Root. So I have created a Qt5 project and instantiated a TApplication. Now I’m trying to create a window that embeds a TCanvas. So I have done the following:

void QtTester::OpenCanvas()
{
    QRect rect = geometry();
    int width = rect.width();
    int height = rect.height();
    int wid = gVirtualX->AddWindow((ULong_t)winId(), width, height);
    m_pTCanvas = new TCanvas("Root canvas", width, height, wid);
    int i=0;
}

But when I call this function I always get a zero as the value for the wid variable. The class owning the function is a QWidget window. I cannot find any reference to why I would be getting a return value of 0 from the AddWindow() call. Just for fun I added another function to paint a canvas (code taken from one of the example .C files, first tested in the root interactive interpreter), and it compiled fine, and the widget opened as a new window, but no data was painted as content. Which I assume means that I am correct in saying that 0 isn’t a valid return value for AddWindow(). The documentation says nothing about this.

Any help would be seriously appreciated.


ROOT Version: Not Provided
Platform: Not Provided
Compiler: Not Provided


Last time I tried (on Windows) with Qt 5.10, this was working just fine:

//______________________________________________________________________________
QRootCanvas::QRootCanvas(QWidget *parent) : QWidget(parent, 0), fCanvas(0)
{
   // QRootCanvas constructor.

   // set options needed to properly update the canvas when resizing the widget
   // and to properly handle context menus and mouse move events
   setAttribute(Qt::WA_PaintOnScreen, false);
   setAttribute(Qt::WA_OpaquePaintEvent, true);
   setAttribute(Qt::WA_NativeWindow, true);
   setUpdatesEnabled(kFALSE);
   setMouseTracking(kTRUE);
   setMinimumSize(300, 200);

   // register the QWidget in TVirtualX, giving its native window id
   int wid = gVirtualX->AddWindow((ULong_t)winId(), width(), height());
   // create the ROOT TCanvas, giving as argument the QWidget registered id
   fCanvas = new TCanvas("Root Canvas", width(), height(), wid);
   TQObject::Connect("TGPopupMenu", "PoppedDown()", "TCanvas", fCanvas, "Update()");
}
1 Like

Thanks. I had seen reference to QRootCanvas but when I went looking for it in files in my include folder I didn’t find anything. I have both a Windows and a Linux system using with Root 5.34/36. I searched the full Root folder for QRootCanvas in the Windows Explorer with “search in files” set and didn’t find it. I then grepped the whole Root folder on the Linux box for the same and didn’t find it. Is there a way to get this functionality back if somehow it was removed?

Oh, sorry, I’m using Qt 5.1.1. Did this come in a later version of Qt? We haven’t upgraded yet.

Well, this is from my own example… I’ll make sure it still works and send you the complete example some time next week (sorry for the delay…)

Sorry, just updated my reply when you answered. We are using 5.1.1 and haven’t updated yet. Was this added after that?

And thanks for the help.

It shouldn’t matter (I think), but I’ll check and I’ll let you know. And note also that ROOT 5 is deprecated and Qt is not supported anymore…

Yeah, what does one do going forward? Are there ways to hook in to Root from Qt even though the support is not going to be there in the library? If not I guess I’ll have to look into another way of doing charting for the future. For now though I do need to figure this one out. Thanks for the reply.

The problem comes from Qt on MacOS. But it should still work on Linux and Windows. And we don’t have the manpower to support Qt on all platforms… Stay tuned

So I’m on Windows 7.

So the attached code below works with Qt 5.6, ROOT 5.34.37 (built with Visual Studio 2013)
simple_canvas.zip (3.6 KB)

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.