Qt Forum

    • Login
    • Search
    • Categories
    • Recent
    • Tags
    • Popular
    • Users
    • Groups
    • Search
    • Unsolved

    Update: Forum Guidelines & Code of Conduct

    Unsolved How to use scrollArea to view camera video in PyQt4

    General and Desktop
    3
    4
    773
    Loading More Posts
    • 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.
    • R
      robotsandi last edited by

      Hi
      I am new in Pyqt4, I design GUI in Qt and convert to pyqt4, now i want to use scroll Area to show camera view in the scroll area.
      this is my code to open camera in the new window.
      def init(self):
      self.capturing = False
      self.c = cv2.VideoCapture(0)

      def startCapture(self):
          print "pressed start"
          self.capturing = True
          cap = self.c
          while(self.capturing):
              ret, frame = cap.read()
              cv2.imshow("Capture", frame)
              cv2.waitKey(5)
          cv2.destroyAllWindows()
      

      Heare is my code to scrollArea design.
      self.scrollArea = QtGui.QScrollArea(self.centralWidget)
      self.scrollArea.setMouseTracking(True)
      self.scrollArea.setWidgetResizable(True)
      self.scrollArea.setObjectName(_fromUtf8("scrollArea"))
      self.scrollAreaWidgetContents = QtGui.QWidget()
      self.scrollAreaWidgetContents.setGeometry(QtCore.QRect(0, 0, 363, 214))
      self.scrollAreaWidgetContents.setObjectName(_fromUtf8("scrollAreaWidgetContents"))

          self.scrollArea.setWidget(self.scrollAreaWidgetContents)
      
      1 Reply Last reply Reply Quote 0
      • SGaist
        SGaist Lifetime Qt Champion last edited by

        Hi,

        You are trying to mix two different GUI library here and that won't go as you expect even if OpenCV might use Qt as backend.

        You should rather convert the frames you capture to a QImage and use a QLabel to show them. Or you could consider using QtMultimedia if it fits your need, then there's no need for OpenCV.

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

        R 1 Reply Last reply Reply Quote 2
        • R
          robotsandi @SGaist last edited by

          @SGaist
          How can i use QtMultimedia in PyQt4.

          mrjj 1 Reply Last reply Reply Quote 0
          • mrjj
            mrjj Lifetime Qt Champion @robotsandi last edited by

            Hi
            Like any other Qt module,
            Something like

            import sys
            from PyQt5.QtWidgets import QApplication, QWidget
            from PyQt5.QtCore import QUrl
            from PyQt5 import QtMultimedia
            from qt_tools import key_text
            
            class Window(QWidget):
                 def __init__(self):
                     super().__init__()
                     self.player = QtMultimedia.QMediaPlayer(self)
                     self.player.setMedia(QUrl.fromLocalFile("xxxxx"))     
                     self.show()
            
                 def keyPressEvent(self, e):
                     key = key_text(e.key())
                     if key == "space":
                         print(self.player.errorString())
                         self.player.play()
            
            app = QApplication(sys.argv)
            window = Window()
            sys.exit(app.exec_())
            

            Note I do not use python :)
            Just used google to find sample.

            1 Reply Last reply Reply Quote 1
            • First post
              Last post