Important: Please read the Qt Code of Conduct -

How to set a transparent Button on QVTKWidget based on QT

  • 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

  • Lifetime Qt Champion

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

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

    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?

  • Lifetime Qt Champion

    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 ?

  • @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.

  • I've just tested it and its working for me


    QHBoxLayout* lay = new QHBoxLayout();
    QPushButton* btn = new QPushButton("TEST TEST", this);
    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

  • 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:


    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.

  • 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)
   = vtk.vtkRenderer()
            self.iren = self.vtkWidget.GetRenderWindow().GetInteractor()
            self.layout = QtWidgets.QHBoxLayout()
            btn = QtWidgets.QPushButton("TEST TEST", self.vtkWidget)
            btn.setStyleSheet("background-color: rgba(255,0,255,128)")
            # Create source
            source = vtk.vtkSphereSource()
            source.SetCenter(0, 0, 0)
            # Create a mapper
            mapper = vtk.vtkPolyDataMapper()
            # Create an actor
            actor = vtk.vtkActor()
    if __name__ == "__main__":
        app = QtWidgets.QApplication(sys.argv)
        window = MainWindow()

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

  • I went as far as editing 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.

Log in to reply