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. QFileDialog - How to load and display image in a QLabel
Qt 6.11 is out! See what's new in the release blog

QFileDialog - How to load and display image in a QLabel

Scheduled Pinned Locked Moved Solved General and Desktop
5 Posts 3 Posters 2.4k Views
  • 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.
  • L Offline
    L Offline
    LT-K101
    wrote on last edited by
    #1

    Hi
    How to load and display an image in a QLabel using QFileDialog. The image paths is working perfectly but after selecting the image, the page exits. The image should display after it is selected.

    from PyQt5 import QtCore, QtGui, QtWidgets
    from PyQt5.QtWidgets import QMainWindow, QAction, qApp, QApplication, QLabel, QFileDialog
    from PyQt5.QtGui import QPixmap
    
    
            self.ui.Display_Button.clicked.connect(self.Load_Display)
    
        def Load_Display(self):
            fname = QFileDialog.getOpenFileName(self, "Choose File", "", "All FIles(*) ;; Images(*.jpeg)")
            pixmap = QPixmap(fname)
            self.ui.Display_label.setPixmap(QPixmap(pixmap))
            self.ui.Display_label.repaint()
    
    
    eyllanescE 1 Reply Last reply
    0
    • L LT-K101

      Hi
      How to load and display an image in a QLabel using QFileDialog. The image paths is working perfectly but after selecting the image, the page exits. The image should display after it is selected.

      from PyQt5 import QtCore, QtGui, QtWidgets
      from PyQt5.QtWidgets import QMainWindow, QAction, qApp, QApplication, QLabel, QFileDialog
      from PyQt5.QtGui import QPixmap
      
      
              self.ui.Display_Button.clicked.connect(self.Load_Display)
      
          def Load_Display(self):
              fname = QFileDialog.getOpenFileName(self, "Choose File", "", "All FIles(*) ;; Images(*.jpeg)")
              pixmap = QPixmap(fname)
              self.ui.Display_label.setPixmap(QPixmap(pixmap))
              self.ui.Display_label.repaint()
      
      
      eyllanescE Offline
      eyllanescE Offline
      eyllanesc
      wrote on last edited by
      #2

      @LT-K101 Change to fname, _ = QFileDialog.getOpenFileName(self, ...)

      If you want me to help you develop some work then you can write to my email: e.yllanescucho@gmal.com.

      L 1 Reply Last reply
      3
      • eyllanescE eyllanesc

        @LT-K101 Change to fname, _ = QFileDialog.getOpenFileName(self, ...)

        L Offline
        L Offline
        LT-K101
        wrote on last edited by
        #3

        @eyllanesc Thanks it worked!. I have a question if you could please assist, I'm using QDateEdit to Popup a calender when the QDateEdit is clicked. Below is what I did but its not working.

        from PyQt5 import QtCore, QtGui, QtWidgets
        from datetime import datetime
        import sys
        
        
        self.dateedit = QtWidgets.QDateEdit(calendarPopup=True)
        self.dateedit.setDateTime(QtCore.QDateTime.currentDateTime())
        
        jsulmJ 1 Reply Last reply
        0
        • L LT-K101

          @eyllanesc Thanks it worked!. I have a question if you could please assist, I'm using QDateEdit to Popup a calender when the QDateEdit is clicked. Below is what I did but its not working.

          from PyQt5 import QtCore, QtGui, QtWidgets
          from datetime import datetime
          import sys
          
          
          self.dateedit = QtWidgets.QDateEdit(calendarPopup=True)
          self.dateedit.setDateTime(QtCore.QDateTime.currentDateTime())
          
          jsulmJ Offline
          jsulmJ Offline
          jsulm
          Lifetime Qt Champion
          wrote on last edited by
          #4

          @LT-K101 said in QFileDialog - How to load and display image in a QLabel:

          but its not working

          You have to set https://doc.qt.io/qt-5/qdatetimeedit.html#calendarPopup-prop if you want a pop-up...

          https://forum.qt.io/topic/113070/qt-code-of-conduct

          L 1 Reply Last reply
          2
          • jsulmJ jsulm

            @LT-K101 said in QFileDialog - How to load and display image in a QLabel:

            but its not working

            You have to set https://doc.qt.io/qt-5/qdatetimeedit.html#calendarPopup-prop if you want a pop-up...

            L Offline
            L Offline
            LT-K101
            wrote on last edited by
            #5

            @jsulm There is an option in the Qt Designer which can be enabled, I did so and the Popup is working perfectly now. Thanks for your response

            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