gVirtualx->AddWindow problem

Hi, I ported a legacy application from ROOT5 and QT4.8 to ROOT6 and QT5.
I used Bertrand’s suggestion (shown below) which compiles and runs.
Problem is, the canvas size remains small and of a fixed size (which was not the old behavior):
I tried to hard-wire different values for the width and height, but no matter what, the size of the canva remains utterly small (something around 100x80 pixels…
Since it worked fine with ROOT6 compiled against Qt4.8.5, am I missing a new recipe here?

Thanks (below Bertrand’s suggested code)

QRootCanvas::QRootCanvas(QWidget *parent, string title) : QWidget(parent, 0), fCanvas(0)
{
   setAttribute     (Qt::WA_PaintOnScreen,    true);
   setAttribute     (Qt::WA_OpaquePaintEvent, true);
   setMinimumSize   (50, 50);
   setUpdatesEnabled(kFALSE);
   setUpdatesEnabled(kTRUE);
   setMouseTracking (kTRUE );

   int wid = gVirtualX->AddWindow((ULong_t)winId(), width(), height());
   this->setGeometry(
                     0,
                     0,
                     parent->width(),
                     parent->height()
                    );

   fCanvas = new TCanvas(title.c_str(), parent->width(), parent->height(), wid);
}

Thanks

Hi,

I’ll try it and let you know.

Cheers, Bertrand.

Bertrand, I guess I know what happens: the QRootCanvas class (as in your original example) overrides the paintEvent private method (as shown here).

void QRootCanvas::paintEvent( QPaintEvent * )
{
   // Handle paint events.

   if (fCanvas)
   {
      fCanvas->Resize();
      fCanvas->Update();
   }
}

Since with Qt5 an annoying message appears on STDOUT, cluttering my formatted ouput, saying

QWidget::paintEngine: Should no longer be called

I thought the the culprit was the fCanvas->Update() call therein, so I altogether removed the paintEvent and the resizeEvent re-implementation from my code, generating the problem I mentioned in my post.

I didn’t notice this immediately because after my removal I didn’t check the result and after a few days I forgot about it. Now I restored them and the code is running as was originally planned.

The question remains: how do I get rid of the annoying > QWidget::paintEngine: Should no longer be called message?

Thanks for your insight.

Hi,

To get rid of this message, you can call setAttribute(Qt::WA_PaintOnScreen, false);, but then there could be issues with the context menus…(just try)

Cheers, Bertrand.

Try this, it works fine for me:

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

   setAttribute(Qt::WA_PaintOnScreen, false);
   setAttribute(Qt::WA_OpaquePaintEvent, true);
   setAttribute(Qt::WA_NativeWindow, true);
   setMinimumSize(300, 200);
   setUpdatesEnabled(kFALSE);
   setMouseTracking(kTRUE);

   // 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()");
}

//______________________________________________________________________________
void QRootCanvas::resizeEvent( QResizeEvent *event )
{
   // Handle resize events.

   if (fCanvas) {
      fCanvas->SetCanvasSize(event->size().width(), event->size().height());
      fCanvas->Resize();
      fCanvas->Update();
   }
}

I’m sorry, but if I set Qt::WA_PaintOnScreen to false, the code compiles and runs but the size of the canvas, within the parent widget, becomes very small and there is no way of making it bigger.

By the way: what should I do to intercept the contextMenu of a TCanvas? I would like to be able to propose users a contextMenu whenever they hover the mouse over the cell of a scatter plot. This requires me to override the ROOT context menu with mine (TQObject::Connect mechanism? If so, how?)

Thanks again for your precious insight.

Dario

Hi Dario,

Here is a complete working example. To make the canvas size fitting the widget, I use this trick (in main.cxx):

   m.setGeometry( 100, 100, 699, 499 );
   m.show();
   m.resize(700, 500);

simple_canvas.tar.gz (2.9 KB)

And to use you own context menu, replace fCanvas->HandleInput(kButton3Down, e->x(), e->y()); in void QRootCanvas::mousePressEvent( QMouseEvent *e ) and/or fCanvas->HandleInput(kButton3Up, e->x(), e->y());
in void QRootCanvas::mouseReleaseEvent( QMouseEvent *e ) with your own code, or any other solution…

Cheers, Bertrand

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