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. [Solved] Questions about the signal handlers' style (old working but not the new way)? [Python PyQt4]
Forum Updated to NodeBB v4.3 + New Features

[Solved] Questions about the signal handlers' style (old working but not the new way)? [Python PyQt4]

Scheduled Pinned Locked Moved General and Desktop
5 Posts 2 Posters 1.1k Views 1 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.
  • M Offline
    M Offline
    madao
    wrote on last edited by
    #1

    Hi,

    I am new to PyQt, but I like it since it is very handy! Glad to be here.

    I am running into a weird issue that the old way of signal handling worked, but the new way failed. Please let me know if I did anything wrong. It is using PyQt4.

    So my application has a main window, and I need to make it pop a QDialog for some warning messages and few buttons that user can interact with (sorta like email I guess). So I create a custom QDialog class, add a QDialogButtonBox with three QPushButton. The idea is when a user click a button, the QDialog will close, and return different int value of exec_() to the main window, so my application can process accordingly.

    What I did (and worked) was:
    @
    self.aButton = QtGui.QPushButton("Afunc")
    self.buttonBox = QtGui.QDialogButtonbox()
    self.aButton.addButton (self.aButton, QtGui.QDialogButtonBox.RejectRole)
    mainLayout.addWidget (self.buttonBox)
    self.connect(self.aButton, QtCore.SIGNAL("clicked()"), self.Afunc)

    def aFunc(self):
    self.setResult(3)
    @

    However, I was told there is a new style to connect buttons, which is below
    @
    self.aButton.clicked.connect(self.aFunc)
    @

    So I changed it, but then I can never get the desired return value 3 when press the A button. Also I noticed if changed the button's role from RejectRole to AcceptRole or ActionRole, it will be worse -- the QDialog will not close, and thus my application did not receive any return value from exec__(). Nothing happened.

    My questions are:

    1. Why the new style did not work? Am I missing something?
    2. Why it has to be RejectRole for the button? I do want some button doing nothing but close the QDialog, pretty much like the OK button, and its default return value is desired. I thought it should be AcceptRole, no?

    Thank you very much!

    [edit: changed for coding tags @ SGaist]

    1 Reply Last reply
    0
    • SGaistS Offline
      SGaistS Offline
      SGaist
      Lifetime Qt Champion
      wrote on last edited by
      #2

      Hi and welcome to devnet,

      The new connection style is only available with Qt 5 so you would also have to use PyQt 5.

      Closing the dialog doing nothing correspond to a "rejection". You should connect the QDialogButtonBox (e.g. accepted, rejected) signals to the corresponding QDialog slot. You can use the clicked signal which has a button parameter to set the result accordingly.

      Hope it helps

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

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

        Hi Sgaist,

        Thank you very much for the help. I did not know the new style is only for Qt 5.

        I am not really getting what you suggested for the signal, so could you please list some codes. Thanks!

        1 Reply Last reply
        0
        • M Offline
          M Offline
          madao
          wrote on last edited by
          #4

          Update:
          I ended up used QHBoxLayout instead of the QDialogButtonBox, and everything worked. Thanks for the help!

          So yeah, the new style works for me in PyQt4, just a note.

          Will close the thread if I can.

          1 Reply Last reply
          0
          • SGaistS Offline
            SGaistS Offline
            SGaist
            Lifetime Qt Champion
            wrote on last edited by
            #5

            What do you mean by QHBoxLayout instead of the QDialogButtonBox ?

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

            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