2

In my app I have two 3D viewports (which inherit QOpenGLWidget) and the user can switch between them by clicking on them. I'd like to highlight the activated viewport is some way, like making a colored frame (border) around it. What's the best way to do this?

frogatto
  • 26,401
  • 10
  • 73
  • 111
3dmodels
  • 83
  • 5
  • 2
    To formulate the question as "what is the best way" is a recipe to never get an answer. It's unclear what factors you take in account in defining "best". It can be infinite amount of ways, hence question is too broad (and as one who work with same combination of software as you do, Qt, and QOpenGLWidget rendering, I'm sure in number of the ways) – Swift - Friday Pie Aug 25 '18 at 07:34
  • 1
    Option 1: make 3D view child of a `QFrame` and change the border style. Option 2: make 3D view child of a `QWidget` and change the background color. (There is often per default a border around child layout of `QWidget` which you even may adjust to your needs.) Option 3: just paint a border in the `paintEvent()` of your 3D view widget. – Scheff's Cat Aug 25 '18 at 07:36
  • 1
    @Scheff Option 3: render border in OpenGl context. Option 4: render border in HUD-like manner in OpenGL overlay context. Option 5: Use QGraphicsScene with QOpenGLWidgets in it and render borders using that scene... Also every of those can be done in several ways. – Swift - Friday Pie Aug 25 '18 at 07:38
  • 1
    Concerning option 3: I once wrote an answer how `paintEvent()` and `paintGL()` are related to each other in [`QOpenGLWidget`](https://stackoverflow.com/a/50857712/7478597) – Scheff's Cat Aug 25 '18 at 07:40
  • 1
    @Swift-FridayPie So many options - she/he will have a hard time to decide which one's the best on her/his own... ;-) – Scheff's Cat Aug 25 '18 at 07:40
  • 1
    ...and I once wrote another answer how to mix OpenGL and `QPainter` paints for an HUD (Head Up Display) [SO: Paint a rect on qglwidget at specifit times](https://stackoverflow.com/a/42420804/7478597). (I did it with `QOpenGLWidget` ignoring that the title mentioned the Qt4 `QGLWidget`.) – Scheff's Cat Aug 25 '18 at 07:43
  • 1
    @Scheff Yeah, that too. would that one work effectively with flexible pipeline? As far as I can tell, as soon as one starts to _actually_ use OpenGL instead of 18 year old OpenGL 1.2 API, most of Qt stuff stops work properly. – Swift - Friday Pie Aug 25 '18 at 07:46
  • 1
    @Swift-FridayPie In daily work, I use OpenGL 3+. I prevented the Qt binding and did my own (because I want to use the GL rendering code without Qt as well). Yepp, OpenGL and `QPainter` is nearly no problem IF you restore the resp. buffers properly. (I.e. When I realized this I was prepared due to the resp. warnings in Qt doc. I inserted back-up and recovering of buffers and other states until `QPainter` (and friends) didn't crash anymore.) ;-) Other issues except these crashes I couldn't observe. – Scheff's Cat Aug 25 '18 at 07:50
  • 1
    @SCheff most issues I met were related to that Qt's code was written with fixed pipeline in mind. If you didn't use their API wrappers, you was in clear waters. – Swift - Friday Pie Aug 25 '18 at 10:12
  • Many thanks. I think I'll choose "Option 1: make 3D view child of a QFrame and change the border style." By the "Best way" I meant by using QT and without inventing my own bicycles. – 3dmodels Aug 25 '18 at 11:58
  • 1
    Yet another option: implement a proxy style to adjust the rendering based on focus. – André Aug 26 '18 at 09:10

1 Answers1

0

Thanks for you sujestions. I understand that there are numerous ways of drawing a border in OpenGL, but my question was about QT built-in methods. So, here are the answers:

Option 1: make 3D view child of a QFrame and change the border style. Yet another option: implement a proxy style to adjust the rendering based on focus.

3dmodels
  • 83
  • 5