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. using QOpenGLWidget as viewPort for QGraphicsView
Forum Updated to NodeBB v4.3 + New Features

using QOpenGLWidget as viewPort for QGraphicsView

Scheduled Pinned Locked Moved Unsolved General and Desktop
6 Posts 2 Posters 898 Views 1 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.
  • S Offline
    S Offline
    Sh.m.z
    wrote on last edited by Sh.m.z
    #1

    Re: using QOpenGLWidget as viewPort for QGraphicsView in Scene doesn't work?

    I had the same problem mentioned by @davecotter, but by using the graphicsView->setViewport(new QOpenGLWidget()) after the mediaPlayer->setMedia(...) the problem is resolved.
    However, I still have a performance problem in playing video using QGraphicsView and QGraphicsVideoItem. It uses 70% of the CPU to just play a MP4 video (1920x1080).
    While, if I substitute the QGraphicsView with a QVideoWidget, the CPU usage drastically drops to ~6%.
    However, the problem is that I have to use a QGraphicsView to play the video because I need to draw some lines and texts over the video based on the user's mouse clicks.
    My OS is macOS 10.15.7 and I am using PyQt5 version 5.15.2. I would appreciate it if someone please help me to know why there is such a difference between the performance of QVideoWidget and QGraphicsVideoItem.
    Is there any particular setting in the QGraphicsVideoItem to improve its rendering performance?
    It could help me to solve this problem.

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

      Hi,

      What machine are you running ?

      Are you testing that with a minimal application ?

      Interested in AI ? www.idiap.ch
      Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

      1 Reply Last reply
      0
      • S Offline
        S Offline
        Sh.m.z
        wrote on last edited by
        #3

        Hi,
        Thanks for your reply.
        I am running the application on MacBook Pro (Retina), 2.4 GHz Dual-Core Intel Core i5 processor, 8 GB 1600 MHz DDR3 memory with Intel Iris 1536 MB graphics.
        It is a minimal application that has only a QGaphicsView to play a full HD video.

        1 Reply Last reply
        0
        • SGaistS Offline
          SGaistS Offline
          SGaist
          Lifetime Qt Champion
          wrote on last edited by
          #4

          Do you have a discrete GPU on that machine ?

          Interested in AI ? www.idiap.ch
          Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

          1 Reply Last reply
          0
          • S Offline
            S Offline
            Sh.m.z
            wrote on last edited by
            #5

            No, I do not have any discrete GPU.

            1 Reply Last reply
            0
            • S Offline
              S Offline
              Sh.m.z
              wrote on last edited by
              #6

              This is the sample code I used from https://stackoverflow.com/questions/53899740/how-to-draw-qtgraphicsview-on-top-of-qvideowidget-with-transparency.

              class Widget(QtWidgets.QWidget):
                  def __init__(self, parent=None):
                      super(Widget, self).__init__(parent)
              
                      self._scene = QtWidgets.QGraphicsScene(self)
              
                      self._gv = QtWidgets.QGraphicsView(self._scene)
                      self._gv.setBackgroundBrush(QtGui.QBrush(QtCore.Qt.lightGray))
              
                      self._videoitem = QGraphicsVideoItem() 
                      self._scene.addItem(self._videoitem)
              
                      self._player = QMediaPlayer(self, QMediaPlayer.VideoSurface)
                      self._player.setVideoOutput(self._videoitem.videoSurface())
                      file = os.path.join(os.path.dirname(__file__), "GOPR0196.MP4")
                      self._player.setMedia(QMediaContent(QtCore.QUrl.fromLocalFile(file)))
              
                      button = QtWidgets.QPushButton("Play")
                      button.clicked.connect(self.play)
              
                      self.resize(640, 480)
                      lay = QtWidgets.QVBoxLayout(self)
                      lay.addWidget(self._gv)
                      lay.addWidget(button)
              
                  def play(self):
                      oglWidget = QOpenGLWidget()
                      self._gv.setViewport(oglWidget)
              
                      if self._player.state() == QMediaPlayer.PlayingState:
                          self._player.pause()
                      else:
                          self._player.play()
              
              if __name__ == '__main__':
                  import sys
                  app = QtWidgets.QApplication(sys.argv)
                  w = Widget()
                  w.show()
                  sys.exit(app.exec_())
              
              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