Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. Language Bindings
  4. [Solved] PyQt Dialog Window Not Popping up in Function
QtWS25 Last Chance

[Solved] PyQt Dialog Window Not Popping up in Function

Scheduled Pinned Locked Moved Language Bindings
8 Posts 3 Posters 8.7k 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.
  • N Offline
    N Offline
    needhelp_gh
    wrote on last edited by
    #1

    Hi,

    I've spent many days trying to figure this out...

    My dialog window is not popping up when being called from inside a function.

    I've done this before & have been successful, but this particular one is not working.

    Could there be a setting I messed up or missed?

    This is my code:

    @from PyQt4 import QtGui, uic, QtCore, Qt

    def MAIN():
    widget = uic.loadUi("/PATH/TO/file.ui")
    widget.show()

    MAIN()@

    (I tried to simplify it as much as possible, but nothing works...)

    But it works if I do this:

    @from PyQt4 import QtGui, uic, QtCore, Qt

    widget = uic.loadUi("/PATH/TO/file.ui")
    widget.show()
    @

    Any ideas? Thanks!!

    If the ui code would be useful, please let me know.


    http://abstrusegoose.com/432

    1 Reply Last reply
    0
    • N Offline
      N Offline
      needhelp_gh
      wrote on last edited by
      #2

      I've also replaced the dialog ui file for a window ui file & same thing...This is quite puzzling.

      Any help would be appreciated!!


      http://abstrusegoose.com/432

      1 Reply Last reply
      0
      • jazzycamelJ Offline
        jazzycamelJ Offline
        jazzycamel
        wrote on last edited by
        #3

        Try the following with your .ui file:

        @
        from PyQt4.QtGui import *
        from PyQt4 import uic

        class MainWindow(QMainWindow):
        def init(self, parent=None):
        QMainWindow.init(self, parent)

            self.ui.uic.loadUi("./example.ui")
            self.ui.show()
        

        if name=="main":
        from sys import argv, exit
        a=QApplication(argv)
        m=MainWindow()
        exit(a.exec_())
        @

        It tends to be better to have an enclosing widget (QWidget, QMainWindow etc.). I don't use UI files very often but this is what I always do.

        Hope it helps.

        For the avoidance of doubt:

        1. All my code samples (C++ or Python) are tested before posting
        2. As of 23/03/20, my Python code is formatted to PEP-8 standards using black from the PSF (https://github.com/psf/black)
        1 Reply Last reply
        0
        • N Offline
          N Offline
          needhelp_gh
          wrote on last edited by
          #4

          Hi,

          Thanks for your reply, but is there any way to do it w/o classes/OOP?


          http://abstrusegoose.com/432

          1 Reply Last reply
          0
          • jazzycamelJ Offline
            jazzycamelJ Offline
            jazzycamel
            wrote on last edited by
            #5

            Try this:

            @
            from PyQt4.QtGui import *
            from PyQt4 import uic
            from sys import argv, exit

            def Main():
            a=QApplication(argv)
            ui=uic.loadUi("./example.ui")
            ui.show()
            return a.exec_()

            Main()
            @

            For the avoidance of doubt:

            1. All my code samples (C++ or Python) are tested before posting
            2. As of 23/03/20, my Python code is formatted to PEP-8 standards using black from the PSF (https://github.com/psf/black)
            1 Reply Last reply
            0
            • N Offline
              N Offline
              needhelp_gh
              wrote on last edited by
              #6

              Thanks again. I'm doing this inside another program, called Autodesk Maya 2012/2013, so that just crashes it with this error message:

              QCoreApplication::exec: The event loop is already running
              QClipboard: Unable to receive an event from the clipboard manager in a reasonable time
              Segmentation fault (core dumped)


              http://abstrusegoose.com/432

              1 Reply Last reply
              0
              • I Offline
                I Offline
                ivica
                wrote on last edited by
                #7

                why would you call Main() twice?

                1 Reply Last reply
                0
                • N Offline
                  N Offline
                  needhelp_gh
                  wrote on last edited by
                  #8

                  Solved. See this "post":http://forums.cgsociety.org/showthread.php?p=7378920#post7378920.


                  http://abstrusegoose.com/432

                  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