QT Button on top of QVTKWidget Mac OS

classic Classic list List threaded Threaded
6 messages Options
Reply | Threaded
Open this post in threaded view
|

QT Button on top of QVTKWidget Mac OS

Matt C
I'm trying to display Qt buttons on top of a QVTKWidget.  This works correct in Linux but using
Mac OS 10.11.16, QT 4.8.7 and VTK 7.0 the buttons are invisible. (I can click them if I know where they are).

I considered drawing the buttons right in VTK but we want to use the QT styling and some of their more complex ui objects. Any suggestions?

The following minimal example shows the problem:
#include <QApplication.h>
#include <QVTKWidget.h>
#include <vtkSphereSource.h>
#include <vtkPolyDataMapper.h>
#include <vtkActor.h>
#include <vtkRenderer.h>
#include <vtkRenderWindow.h>
#include <vtkRenderer.h>
int main( int argc, char **argv )
{
  QApplication app( argc, argv );
  QVTKWidget widget;
  widget.resize(640,384);
#if QT_VERSION < 0x040000
 app.setMainWidget(&widget);
#endif
  vtkRenderer *renderer = vtkRenderer::New();
  vtkRenderWindow *renderWindow = vtkRenderWindow::New();
  renderWindow->AddRenderer(renderer);
  widget.SetRenderWindow(renderWindow);

  QLayout* gridLayout = new QGridLayout(&widget);
  QPushButton button("Should show up");
  button.raise();
  button.raise();
  button.raise();

  gridLayout->addWidget(&button);
  widget.setLayout(gridLayout);

  widget.show();
  app.exec();
  return 0;
}
Reply | Threaded
Open this post in threaded view
|

Re: QT Button on top of QVTKWidget Mac OS

Matt C
I tried with QT 5.5.1 with the same results.

Have anyone had success overlaying QT Widgets on a QVTKWidget on Mac OS?
Reply | Threaded
Open this post in threaded view
|

Re: QT Button on top of QVTKWidget Mac OS

Clinton Stimpson

----- On Oct 19, 2016, at 7:48 AM, Matt C [hidden email] wrote:

> I tried with QT 5.5.1 with the same results.
>
> Have anyone had success overlaying QT Widgets on a QVTKWidget on Mac OS?
>
>

You are probably seeing the issue described here:
https://bugreports.qt.io/browse/QTBUG-7140

and on the developers mailing list, a path forward to address it:
http://lists.qt-project.org/pipermail/development/2016-October/027479.html

Clint
_______________________________________________
Powered by www.kitware.com

Visit other Kitware open-source projects at http://www.kitware.com/opensource/opensource.html

Please keep messages on-topic and check the VTK FAQ at: http://www.vtk.org/Wiki/VTK_FAQ

Search the list archives at: http://markmail.org/search/?q=vtkusers

Follow this link to subscribe/unsubscribe:
http://public.kitware.com/mailman/listinfo/vtkusers
Reply | Threaded
Open this post in threaded view
|

Re: QT Button on top of QVTKWidget Mac OS

Matt C
Thanks so much.  That seems to be the issue. I don't know why I couldn't find that bug report on the Qt forum.  

Based on the comments in the bug and stack overflow (http://stackoverflow.com/questions/26944831/using-qvtkwidget-and-qopenglwidget-in-the-same-ui) I will try creating custom QVTKWidget3 which uses QOpenGLWidget instead.


Reply | Threaded
Open this post in threaded view
|

Re: QT Button on top of QVTKWidget Mac OS

Sean McBride
In reply to this post by Matt C
On Tue, 18 Oct 2016 09:04:08 -0700, Matt C said:

>I'm trying to display Qt buttons on top of a QVTKWidget.  This works correct
>in Linux but using
>Mac OS 10.11.16, QT 4.8.7 and VTK 7.0 the buttons are invisible. (I can
>click them if I know where they are).

The canonical example of overlaying Cocoa controls on OpenGL content is:
<https://developer.apple.com/library/content/samplecode/LayerBackedOpenGLView/Introduction/Intro.html>

Basically, you need to use not only NSViews but CALayers also.  VTK includes an NSView subclass, but does not include any CALayer subclass.  *It's something I'm hoping to do one day when I miraculously have free time.)  But it's not too hard to make your own CAOpenGLLayer subclass and tell the vtkrenderwindow to draw into it.  I know nothing about Qt, so getting that into the mix will be another wrinkle I'm sure!

Cheers,

--
____________________________________________________________
Sean McBride, B. Eng                 [hidden email]
Rogue Research                        www.rogue-research.com
Mac Software Developer              Montréal, Québec, Canada


_______________________________________________
Powered by www.kitware.com

Visit other Kitware open-source projects at http://www.kitware.com/opensource/opensource.html

Please keep messages on-topic and check the VTK FAQ at: http://www.vtk.org/Wiki/VTK_FAQ

Search the list archives at: http://markmail.org/search/?q=vtkusers

Follow this link to subscribe/unsubscribe:
http://public.kitware.com/mailman/listinfo/vtkusers
Reply | Threaded
Open this post in threaded view
|

Re: QT Button on top of QVTKWidget Mac OS

Matt C
I've got it working now using the QVtkWidget3 code from the stackoverflow post above.  I had to upgrade to Qt 5.5 to support this.

I did hit a couple of issues
 - On the MacBook retina display the sizing was 1/2 size because it uses a size parameter that no longer applies  This is a known bug with solution: http://stackoverflow.com/questions/39455504/qt-mainwindow-with-qopenglwidget-in-retina-display-displays-wrong-size

 - I had to call QSurfaceFormat::setDefaultFormat() before constructing the QApplication which is only required for Mac OS and is noted on http://doc.qt.io/qt-5/qopenglwidget.html

- Was trying to use a PCLVisualizer to create the render window but it only support a vtkrenderer so am going back to using straight vtk.