Touch screen



  • We are trying out different sdk's to finally decide what would suit our project the best. I'm now about to try out qt and in my first test I would like to stream a video and make my small test-app work with the touch-screen.

    A pc will be connected via hdmi to the touch-screen. The video app (below) is already working and next step would be to try the touch functionality.

    Haven't had the chance to try it yet but before I do I wonder if there are any general considerations to make it work.
    If I am not mistaken I read that in order to get touch to work I need to connect a usb-cable from the pc to the touch-screen.
    Will it most likely work out of the box after that or what steps do I need to consider after connecting the usb between pc and touchscreen? Touchscreen use PCAP Touch technology if that matters (newbie on this matter).

    Thanks

    === Video app where I would like the meny buttons etc to work with touch ===
    class MainWindow(QMainWindow):

    def __init__(self):
        super(MainWindow, self).__init__()
    
        self.playlist = QMediaPlaylist()
        self.player = QMediaPlayer()
        
    
        # Setting QToolBar
        toolBar = QToolBar()
        self.addToolBar(toolBar)
    
        fileMenu = self.menuBar().addMenu("&File")
        openAction = QAction(QIcon.fromTheme("document-open"),
                             "&Open...", self, shortcut=QKeySequence.Open,
                             triggered=self.open)
        fileMenu.addAction(openAction)
        exitAction = QAction(QIcon.fromTheme("application-exit"), "E&xit",
                             self, shortcut="Ctrl+Q", triggered=self.close)
        fileMenu.addAction(exitAction)
    
        playMenu = self.menuBar().addMenu("&Play")
        playIcon = self.style().standardIcon(QStyle.SP_MediaPlay)
        self.playAction = toolBar.addAction(playIcon, "Play")
        self.playAction.triggered.connect(self.player.play)
        playMenu.addAction(self.playAction)
    
        previousIcon = self.style().standardIcon(QStyle.SP_MediaSkipBackward)
        self.previousAction = toolBar.addAction(previousIcon, "Previous")
        self.previousAction.triggered.connect(self.previousClicked)
        playMenu.addAction(self.previousAction)
    
        pauseIcon = self.style().standardIcon(QStyle.SP_MediaPause)
        self.pauseAction = toolBar.addAction(pauseIcon, "Pause")
        self.pauseAction.triggered.connect(self.player.pause)
        playMenu.addAction(self.pauseAction)
    
        nextIcon = self.style().standardIcon(QStyle.SP_MediaSkipForward)
        self.nextAction = toolBar.addAction(nextIcon, "Next")
        self.nextAction.triggered.connect(self.playlist.next)
        playMenu.addAction(self.nextAction)
    
        stopIcon = self.style().standardIcon(QStyle.SP_MediaStop)
        self.stopAction = toolBar.addAction(stopIcon, "Stop")
        self.stopAction.triggered.connect(self.player.stop)
        playMenu.addAction(self.stopAction)
    
        # Setting the QSlider
        self.volSlider = QSlider()
        self.volSlider.setOrientation(Qt.Horizontal)
        self.volSlider.setMinimum(0)
        self.volSlider.setMaximum(100)
        self.volSlider.setFixedWidth(120)
        self.volSlider.setValue(self.player.volume())
        self.volSlider.setTickInterval(10)
        self.volSlider.setTickPosition(QSlider.TicksBelow)
        self.volSlider.setToolTip("Volume")
        self.volSlider.valueChanged.connect(self.player.setVolume)
        toolBar.addWidget(self.volSlider)
    
        aboutMenu = self.menuBar().addMenu("&About")
        aboutQtAct = QAction("About &Qt", self, triggered=qApp.aboutQt)
        aboutMenu.addAction(aboutQtAct)
    
        self.videoWidget = QVideoWidget()
        self.setCentralWidget(self.videoWidget)
        self.player.setPlaylist(self.playlist);
        self.player.stateChanged.connect(self.updateButtons)
        self.player.setVideoOutput(self.videoWidget);
    
        self.updateButtons(self.player.state())
    
        self.playlist.addMedia(QUrl("https://www.radiantmediaplayer.com/media/bbb-360p.mp4"))
        self.player.play()
    
    def open(self):
        fileDialog = QFileDialog(self)
        supportedMimeTypes = ["video/mp4", "*.*"]
        fileDialog.setMimeTypeFilters(supportedMimeTypes)
        moviesLocation = QStandardPaths.writableLocation(QStandardPaths.MoviesLocation)
        fileDialog.setDirectory(moviesLocation)
        if fileDialog.exec_() == QDialog.Accepted:
            self.playlist.addMedia(fileDialog.selectedUrls()[0])
            self.playlist.addMedia(QUrl("https://www.radiantmediaplayer.com/media/bbb-360p.mp4"))
            self.player.play()
    
    def previousClicked(self):
        # Go to previous track if we are within the first 5 seconds of playback
        # Otherwise, seek to the beginning.
        if self.player.position() <= 5000:
            self.playlist.previous();
        else:
            self.player.setPosition(0);
    
    def updateButtons(self, state):
        mediaCount = self.playlist.mediaCount()
        self.playAction.setEnabled(mediaCount > 0
            and state != QMediaPlayer.PlayingState)
        self.pauseAction.setEnabled(state == QMediaPlayer.PlayingState)
        self.stopAction.setEnabled(state != QMediaPlayer.StoppedState)
        self.previousAction.setEnabled(self.player.position() > 0)
        self.nextAction.setEnabled(mediaCount > 1)
    

    if name == 'main':
    app = QApplication(sys.argv)
    mainWin = MainWindow()
    mainWin.resize(800, 600)
    mainWin.show()
    sys.exit(app.exec_())


Log in to reply