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. Button wrong event
Qt 6.11 is out! See what's new in the release blog

Button wrong event

Scheduled Pinned Locked Moved Unsolved General and Desktop
3 Posts 1 Posters 422 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.
  • M Offline
    M Offline
    MAX001
    wrote on last edited by MAX001
    #1

    I want to click on the import button to open the image. How can I do this correctly in Python? Now my button is pressed by itself, the picture turns out to be opened, but the event does not work again.

    To open a picture I have the following code

    def display_image():
        load_image = QLabel()
        image_name = QFileDialog.getOpenFileName(load_image, 'Open file', '\\Images', "Image Files (*.jpg *.gif *.bmp *.png)")
        loaded_image = QPixmap(image_name[0])
        load_image.setPixmap(loaded_image)
        load_image.setScaledContents(True)
        return load_image
    

    And, accordingly, such a function call

        image_import_btn.clicked.connect(grid_image_detect.addWidget(display_image(), 0, 1))
        image_import_btn.clicked.connect(grid_image_detect.addWidget(display_image(), 0, 2))
        image_detect.setLayout(grid_image_detect)
    

    I tried to store the result in a variable
    I've tried calling the function on click, but it doesn't work.

    image_import_btn.clicked.connect(display_image())
    

    Returns
    Traceback (most recent call last):
    File "main.py", line 117, in goto_image_obj_detect image_obj_detect()
    File "main.py", line 1020, in image_obj_detect image_import_btn.clicked.connect(display_image())
    TypeError: 'PySide6.QtCore.QObject.connect' called with wrong argument types:
    PySide6.QtCore.QObject.connect(QPushButton, str, QLabel)
    Supported signatures:
    PySide6.QtCore.QObject.connect(PySide6.QtCore.QObject, bytes, Callable, PySide6.QtCore.Qt.ConnectionType = PySide6.QtCore.Qt.ConnectionType.AutoConnection)
    PySide6.QtCore.QObject.connect(bytes, Callable, PySide6.QtCore.Qt.ConnectionType = PySide6.QtCore.Qt.ConnectionType.AutoConnection)
    PySide6.QtCore.QObject.connect(bytes, PySide6.QtCore.QObject, bytes, PySide6.QtCore.Qt.ConnectionType = PySide6.QtCore.Qt.ConnectionType.AutoConnection)
    PySide6.QtCore.QObject.connect(PySide6.QtCore.QObject, bytes, bytes, PySide6.QtCore.Qt.ConnectionType = PySide6.QtCore.Qt.ConnectionType.AutoConnection)
    PySide6.QtCore.QObject.connect(PySide6.QtCore.QObject, PySide6.QtCore.QMetaMethod, PySide6.QtCore.QObject, PySide6.QtCore.QMetaMethod, PySide6.QtCore.Qt.ConnectionType = PySide6.QtCore.Qt.ConnectionType.AutoConnection)
    PySide6.QtCore.QObject.connect(PySide6.QtCore.QObject, bytes, PySide6.QtCore.QObject, bytes, PySide6.QtCore.Qt.ConnectionType = PySide6.QtCore.Qt.ConnectionType.AutoConnection)

    M 1 Reply Last reply
    0
    • M MAX001

      I want to click on the import button to open the image. How can I do this correctly in Python? Now my button is pressed by itself, the picture turns out to be opened, but the event does not work again.

      To open a picture I have the following code

      def display_image():
          load_image = QLabel()
          image_name = QFileDialog.getOpenFileName(load_image, 'Open file', '\\Images', "Image Files (*.jpg *.gif *.bmp *.png)")
          loaded_image = QPixmap(image_name[0])
          load_image.setPixmap(loaded_image)
          load_image.setScaledContents(True)
          return load_image
      

      And, accordingly, such a function call

          image_import_btn.clicked.connect(grid_image_detect.addWidget(display_image(), 0, 1))
          image_import_btn.clicked.connect(grid_image_detect.addWidget(display_image(), 0, 2))
          image_detect.setLayout(grid_image_detect)
      

      I tried to store the result in a variable
      I've tried calling the function on click, but it doesn't work.

      image_import_btn.clicked.connect(display_image())
      

      Returns
      Traceback (most recent call last):
      File "main.py", line 117, in goto_image_obj_detect image_obj_detect()
      File "main.py", line 1020, in image_obj_detect image_import_btn.clicked.connect(display_image())
      TypeError: 'PySide6.QtCore.QObject.connect' called with wrong argument types:
      PySide6.QtCore.QObject.connect(QPushButton, str, QLabel)
      Supported signatures:
      PySide6.QtCore.QObject.connect(PySide6.QtCore.QObject, bytes, Callable, PySide6.QtCore.Qt.ConnectionType = PySide6.QtCore.Qt.ConnectionType.AutoConnection)
      PySide6.QtCore.QObject.connect(bytes, Callable, PySide6.QtCore.Qt.ConnectionType = PySide6.QtCore.Qt.ConnectionType.AutoConnection)
      PySide6.QtCore.QObject.connect(bytes, PySide6.QtCore.QObject, bytes, PySide6.QtCore.Qt.ConnectionType = PySide6.QtCore.Qt.ConnectionType.AutoConnection)
      PySide6.QtCore.QObject.connect(PySide6.QtCore.QObject, bytes, bytes, PySide6.QtCore.Qt.ConnectionType = PySide6.QtCore.Qt.ConnectionType.AutoConnection)
      PySide6.QtCore.QObject.connect(PySide6.QtCore.QObject, PySide6.QtCore.QMetaMethod, PySide6.QtCore.QObject, PySide6.QtCore.QMetaMethod, PySide6.QtCore.Qt.ConnectionType = PySide6.QtCore.Qt.ConnectionType.AutoConnection)
      PySide6.QtCore.QObject.connect(PySide6.QtCore.QObject, bytes, PySide6.QtCore.QObject, bytes, PySide6.QtCore.Qt.ConnectionType = PySide6.QtCore.Qt.ConnectionType.AutoConnection)

      M Offline
      M Offline
      MAX001
      wrote on last edited by
      #2

      Correct call is

      image_import_btn.clicked.connect(display_image)
      

      But how I can add that image in the grid correctly?

      1 Reply Last reply
      0
      • M Offline
        M Offline
        MAX001
        wrote on last edited by MAX001
        #3

        Such call helped me

            from functools import partial
            image_import_btn.clicked.connect(partial(display_image, grid_image_detect))
        

        Maybe is more professional call?

        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