Results 1 to 3 of 3

Thread: Close window ( Doubt )

Hybrid View

Previous Post Previous Post   Next Post Next Post
  1. #1
    Join Date
    Feb 2012
    Posts
    2
    Qt products
    Qt4
    Platforms
    Unix/X11

    Wink Close window ( Doubt )

    Hi Guys!

    I'm hours trying to solve this code .... how do I close the first by window the X title bar button...popup and close together?

    Obs: (I'm using PyQt4)



    Qt Code:
    1. #!/usr/bin/env python
    2. #-*- coding: utf-8 -*-
    3.  
    4. import sys
    5. from PyQt4.QtGui import *
    6. from PyQt4.QtCore import *
    7.  
    8.  
    9. class Mainw(object):
    10. def __init__(self, MainWindow):
    11. super(Mainw, self).__init__()
    12.  
    13. self.cw = QWidget(MainWindow)
    14.  
    15. self.btn1 = QPushButton("Popup", self.cw)
    16. MainWindow.setCentralWidget(self.cw)
    17.  
    18. self.btn1.setGeometry(QRect(0, 0, 100, 30))
    19.  
    20.  
    21. QObject.connect(self.btn1, SIGNAL("clicked()"), self.openpopup)
    22.  
    23. def openpopup(self):
    24. self.pop = QWidget()
    25. self.pop.setGeometry(QRect(100, 100, 400, 200))
    26. self.pop.show()
    27.  
    28.  
    29.  
    30. if __name__ == "__main__":
    31. app = QApplication(sys.argv)
    32. MainWindow = QMainWindow()
    33. main = Mainw(MainWindow)
    34. MainWindow.show()
    35. sys.exit(app.exec_())
    To copy to clipboard, switch view to plain text mode 

  2. #2
    Join Date
    Mar 2009
    Location
    Brisbane, Australia
    Posts
    7,729
    Thanks
    13
    Thanked 1,610 Times in 1,537 Posts
    Qt products
    Qt4 Qt5
    Platforms
    Unix/X11 Windows
    Wiki edits
    17

    Default Re: Close window ( Doubt )

    Reimplement the main window closeEvent() and close it explicitly.... at least you could if your code was taking a traditional approach to subclassing QMainWindow.

  3. #3
    Join Date
    Feb 2012
    Posts
    2
    Qt products
    Qt4
    Platforms
    Unix/X11

    Default Re: Close window ( Doubt )

    Solved.

    The function closeEvent() is inappropriate for this case.
    I just created a kinship between the windows to make this possible. The closeEvent () now comes as a complement.

    Qt Code:
    1. #!/usr/bin/env python
    2. #-*- coding: utf-8 -*-
    3.  
    4. import sys
    5. from PyQt4.QtGui import *
    6. from PyQt4.QtCore import *
    7.  
    8.  
    9. class popup(QMainWindow):
    10. def __init__(self,parent=None): # Parentesco
    11. super(popup,self).__init__(parent)
    12.  
    13.  
    14. self.setWindowTitle("Janela Popup")
    15.  
    16.  
    17. self.setMinimumSize(400 , 400)
    18.  
    19.  
    20.  
    21. class Mainw(QMainWindow):
    22. def __init__(self, parent=None):
    23. super(Mainw, self).__init__(parent)
    24.  
    25.  
    26. self.setMinimumSize(400 , 400)
    27.  
    28.  
    29. self.setWindowTitle("Janela Principal")
    30.  
    31. self.btn1 = QPushButton("Popup", self)
    32.  
    33. self.btn1.setGeometry(QRect(100, 50, 200, 200))
    34.  
    35. QObject.connect(self.btn1, SIGNAL("clicked()"), self.openpopup)
    36.  
    37. def openpopup(self):
    38. pop = popup(self)
    39. pop.show()
    40.  
    41.  
    42.  
    43. if __name__ == "__main__":
    44. app = QApplication(sys.argv)
    45. main = Mainw()
    46. main.show()
    47. sys.exit(app.exec_())
    To copy to clipboard, switch view to plain text mode 

Similar Threads

  1. Qt4 - How to close a window?
    By ankeetguha in forum Newbie
    Replies: 1
    Last Post: 30th May 2011, 09:42
  2. close application window
    By seltra in forum Newbie
    Replies: 5
    Last Post: 8th October 2010, 19:12
  3. Replies: 9
    Last Post: 16th May 2010, 16:21
  4. close window signal
    By jano_alex_es in forum Newbie
    Replies: 5
    Last Post: 22nd May 2009, 10:10
  5. How to close parent window from child window?
    By montylee in forum Qt Programming
    Replies: 5
    Last Post: 14th October 2008, 11:40

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Qt is a trademark of The Qt Company.