Important: Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/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

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

    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?


  • Lifetime Qt Champion

    @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 ?



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

    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



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



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



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


Log in to reply