Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. How to set a transparent Button on QVTKWidget based on QT
Forum Updated to NodeBB v4.3 + New Features

How to set a transparent Button on QVTKWidget based on QT

Scheduled Pinned Locked Moved Unsolved General and Desktop
9 Posts 4 Posters 1.5k Views 2 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • D Offline
    D Offline
    dffffaa
    wrote on last edited by dffffaa
    #1

    Just like this pic shows.Although I set the button rgba(x,x,x,40) which is transparent in my code,the button named “Adjust” is not transparent in the blue QVTKWidget .Or how to make the picture's black background in Qvtkwidget disappeared
    a1.jpg a2.jpg

    1 Reply Last reply
    0
    • mrjjM Offline
      mrjjM Offline
      mrjj
      Lifetime Qt Champion
      wrote on last edited by
      #2

      Hi
      Im not sure its supported with QVTKWidget as its does other type of rendering internally.

      D 1 Reply Last reply
      0
      • mrjjM mrjj

        Hi
        Im not sure its supported with QVTKWidget as its does other type of rendering internally.

        D Offline
        D Offline
        dffffaa
        wrote on last edited by
        #3

        @mrjj said in How to set a transparent Button on QVTKWidget based on QT:

        Hi
        Im not sure its supported with QVTKWidget as its does other type of rendering internally.

        Hello,Sir/Madam, do you mean I should change the background by a type of rendering in vtk?

        mrjjM 1 Reply Last reply
        0
        • D dffffaa

          @mrjj said in How to set a transparent Button on QVTKWidget based on QT:

          Hi
          Im not sure its supported with QVTKWidget as its does other type of rendering internally.

          Hello,Sir/Madam, do you mean I should change the background by a type of rendering in vtk?

          mrjjM Offline
          mrjjM Offline
          mrjj
          Lifetime Qt Champion
          wrote on last edited by
          #4

          @dffffaa
          Hi
          i mean that Qt needs to control the composite drawing to be able to
          show a widget transparently.

          So i was wondering if VTK would not have the same
          issue as openGL and transparent widgets ?

          1 Reply Last reply
          0
          • gde23G Offline
            gde23G Offline
            gde23
            wrote on last edited by
            #5

            @mrjii yes, the VTK Widget also uses OpenGL for rendering.

            However I've already placed transparent widgets on top of OpenGL Widgets and its working just fine.

            1 Reply Last reply
            1
            • gde23G Offline
              gde23G Offline
              gde23
              wrote on last edited by gde23
              #6

              I've just tested it and its working for me

              vtk.png

              QHBoxLayout* lay = new QHBoxLayout();
              QPushButton* btn = new QPushButton("TEST TEST", this);
              m_vtk_widget->setLayout(lay);
              lay->addWidget(btn);
              btn->setStyleSheet("background-color: rgba(255,0,255,128)");
              

              Edit: I need to mention that its a QVTKOpenGLNativeWidget, so maygbe this makes a differance? Os is Debian with Qt 5.14.2

              1 Reply Last reply
              2
              • B Offline
                B Offline
                BrianK
                wrote on last edited by BrianK
                #7

                Replying to this topic because I have the exact same transparency issue. Using the same code to draw a button with transparency, and also adding a widget area to highlight another issue when resizing with QSplitter:

                Capture.JPG

                The widget color switches to a dark pink when I resize the window, but it slowly changes to light pink when I resize the widgets with QSplitter, until I resize the window, then it instantly get back to a dark pink. Also, no transparency.

                Resizing fast with QSplitter draws over the overlay widgets, not sure if this is related or a completely different issue. It fades each time I move the handle, but not completely. It takes 3 or 4 iterations to "clean".

                Current implementation is done with vtk 8.2, PyQt and Qt 5.12.5

                Any idea of what is causing these issues?

                Edit: the drawing over the widgets only happens when resizing with QSplitter. Resizing the window looks clean.

                1 Reply Last reply
                0
                • B Offline
                  B Offline
                  BrianK
                  wrote on last edited by
                  #8

                  Ok, so I tried both Pyside2 and PyQt5, created a new environment and used the versions: vtk 9 and Qt 5.15.2.

                  Exact same behavior. I also tested the versions at runtime to make sure it wasn't me.

                  I also stripped it down to this simple Python example:

                  import sys, os
                  import vtk
                  from PyQt5 import QtCore, QtWidgets, QtGui
                  import PyQt5
                  from vtk.qt.QVTKRenderWindowInteractor import QVTKRenderWindowInteractor
                  
                  dirname = os.path.dirname(PyQt5.__file__)
                  plugin_path = os.path.join(dirname, 'plugins', 'platforms')
                  os.environ['QT_QPA_PLATFORM_PLUGIN_PATH'] = plugin_path
                  
                  
                  class MainWindow(QtWidgets.QMainWindow):
                  
                      def __init__(self, parent=None):
                          QtWidgets.QMainWindow.__init__(self, parent)
                  
                          self.widget = QtWidgets.QWidget()
                          self.vl = QtWidgets.QVBoxLayout()
                          self.vtkWidget = QVTKRenderWindowInteractor(self.widget)
                          self.vl.addWidget(self.vtkWidget)
                  
                          self.ren = vtk.vtkRenderer()
                          self.vtkWidget.GetRenderWindow().AddRenderer(self.ren)
                          self.iren = self.vtkWidget.GetRenderWindow().GetInteractor()
                  
                          self.layout = QtWidgets.QHBoxLayout()
                          self.vtkWidget.setLayout(self.layout)
                          btn = QtWidgets.QPushButton("TEST TEST", self.vtkWidget)
                          btn.setStyleSheet("background-color: rgba(255,0,255,128)")
                          self.layout.addWidget(btn)
                  
                          # Create source
                          source = vtk.vtkSphereSource()
                          source.SetCenter(0, 0, 0)
                          source.SetRadius(5.0)
                  
                          # Create a mapper
                          mapper = vtk.vtkPolyDataMapper()
                          mapper.SetInputConnection(source.GetOutputPort())
                  
                          # Create an actor
                          actor = vtk.vtkActor()
                          actor.SetMapper(mapper)
                  
                          self.ren.AddActor(actor)
                  
                          self.ren.ResetCamera()
                  
                          self.widget.setLayout(self.vl)
                          self.setCentralWidget(self.widget)
                  
                          self.show()
                          self.iren.Initialize()
                          self.iren.Start()
                  
                  
                  if __name__ == "__main__":
                      app = QtWidgets.QApplication(sys.argv)
                      window = MainWindow()
                      sys.exit(app.exec_())
                  

                  No transparency. Same strange change in color when resizing the window and having the mouse cursor over the button.

                  1 Reply Last reply
                  0
                  • B Offline
                    B Offline
                    BrianK
                    wrote on last edited by
                    #9

                    I went as far as editing QVTKRenderWindowInteractor.py that ships with VTK.

                    The original file is using either QWidget or QGLWidget as its base class, default being QWidget.
                    I changed it to use QOpenGLWidget.

                    I tried with the 3 different base classes: exact same behavior.

                    1 Reply Last reply
                    0

                    • Login

                    • Login or register to search.
                    • First post
                      Last post
                    0
                    • Categories
                    • Recent
                    • Tags
                    • Popular
                    • Users
                    • Groups
                    • Search
                    • Get Qt Extensions
                    • Unsolved