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. Include a button to open .tif image
Forum Updated to NodeBB v4.3 + New Features

Include a button to open .tif image

Scheduled Pinned Locked Moved Solved General and Desktop
7 Posts 3 Posters 492 Views 2 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.
  • J Offline
    J Offline
    john_hobbyist
    wrote on 4 Jan 2021, 15:22 last edited by
    #1

    Hello,

    I use this code: https://github.com/kklmn/OrthoView/blob/master/OrthoView.py

    what changes should I do, so that I can import the image file via putting a button and choosing the file. Because now I use the image file by putting the path into the code. I need to open the file through a button in order to choose different images when I run the code... I am reading this code: https://www.tutorialspoint.com/pyqt/pyqt_qfiledialog_widget.htm in order to understand the basics... Thank you

    P 1 Reply Last reply 4 Jan 2021, 15:34
    0
    • J john_hobbyist
      4 Jan 2021, 15:22

      Hello,

      I use this code: https://github.com/kklmn/OrthoView/blob/master/OrthoView.py

      what changes should I do, so that I can import the image file via putting a button and choosing the file. Because now I use the image file by putting the path into the code. I need to open the file through a button in order to choose different images when I run the code... I am reading this code: https://www.tutorialspoint.com/pyqt/pyqt_qfiledialog_widget.htm in order to understand the basics... Thank you

      P Offline
      P Offline
      Pl45m4
      wrote on 4 Jan 2021, 15:34 last edited by
      #2

      @john_hobbyist

      The solution already is on your linked site:

      Use QFileDialog to pick the image and trigger the dialog with your button.

      self.btn = QPushButton("QFileDialog static method demo")
      self.btn.clicked.connect(self.getfile)
      
      def getfile(self):
            fname = QFileDialog.getOpenFileName(self, 'Open file', 'C:\\',"Image files (*.jpg *.gif)")
            // DO SOMETHING WITH YOUR IMG
      

      If debugging is the process of removing software bugs, then programming must be the process of putting them in.

      ~E. W. Dijkstra

      1 Reply Last reply
      4
      • J Offline
        J Offline
        john_hobbyist
        wrote on 4 Jan 2021, 19:58 last edited by
        #3

        I added them, but I do no see any button to open and choose file

        M 1 Reply Last reply 4 Jan 2021, 20:06
        0
        • J john_hobbyist
          4 Jan 2021, 19:58

          I added them, but I do no see any button to open and choose file

          M Offline
          M Offline
          mrjj
          Lifetime Qt Champion
          wrote on 4 Jan 2021, 20:06 last edited by
          #4

          @john_hobbyist
          Hi
          well did you add the button to your main screen ?
          To a layout most likely.

          Just creating the button wont show it anywhere :)

          1 Reply Last reply
          1
          • J Offline
            J Offline
            john_hobbyist
            wrote on 4 Jan 2021, 21:00 last edited by john_hobbyist 1 Apr 2021, 21:00
            #5

            If you mean this:

            layout.addWidget(self.btn)
            

            I have added it.

            M 1 Reply Last reply 4 Jan 2021, 21:15
            0
            • J john_hobbyist
              4 Jan 2021, 21:00

              If you mean this:

              layout.addWidget(self.btn)
              

              I have added it.

              M Offline
              M Offline
              mrjj
              Lifetime Qt Champion
              wrote on 4 Jan 2021, 21:15 last edited by
              #6

              @john_hobbyist
              Yep that seems ok.

              1 Reply Last reply
              1
              • J Offline
                J Offline
                john_hobbyist
                wrote on 4 Jan 2021, 21:17 last edited by john_hobbyist 1 Apr 2021, 21:37
                #7

                But I cannot see the button to open file...
                update: Ok I fixed it! Thanks a lot for your time...

                This error:

                NameError: name 'QFileDialog' is not defined
                

                means that I need to import something from PyQt5 ?

                Answer: Yes :-)

                1 Reply Last reply
                1

                1/7

                4 Jan 2021, 15:22

                • Login

                • Login or register to search.
                1 out of 7
                • First post
                  1/7
                  Last post
                0
                • Categories
                • Recent
                • Tags
                • Popular
                • Users
                • Groups
                • Search
                • Get Qt Extensions
                • Unsolved