0

So I'm trying to build a config-setting dialog box for my application. I laid it out in QT Designer, like a lot of posts here recommended. It came out looking really nice. I generated the magic .py code using

pyuic5 -x joeconfig.ui -o ui_joeconfig.py

A magical set of loading lines gave me this as a variation on the normal starting routine:

from ui_joeconfig import Ui_Configuration

app = QApplication(sys.argv)
window = QMainWindow()
ui = Ui_Configuration()
ui.setupUi(window)

This setup allowed me to fill out all my interface labels and text boxes by prefacing their names with "ui.", like this:

ui.tvEdit.setText(cfg['mediadirs']['TV'])
ui.moviesEdit.setText(cfg['mediadirs']['Movies'])
ui.downloadEdit.setText(cfg['mediadirs']['Downloads'])

Now comes the dreaded "Close Dialog" button.

This is going to be popped open from the main app, so it should only close itself, not quit the application. I've tried every combination of quit, close, and hide methods I could find. I've been working on this for hours, something that seems so trivial.

# ui.cancelButton.clicked.connect(AAAARGH)
#                                 ^^^^^^^----- WTF goes here?
#

Can somebody help a fellow out? I'm going a bit nuts trying to solve this. There aren't too many PyQt5 examples out there, compared to PyQt4. And I'm useless when it comes to trying to read the original Qt5 C++ documentation.

Thanks in advance.

Dito
  • 182
  • 3
  • 12
  • Try with `ui.cancelButton.clicked.connect(window.close)` – eyllanesc Nov 10 '17 at 17:48
  • You made it look so easy. Sigh. I should have asked hours earlier. I'll mark it correct! – Dito Nov 10 '17 at 18:06
  • Post your answer and justify why it should be done in that way. :P – eyllanesc Nov 10 '17 at 18:08
  • Why dialogs should be laid out using QT-Designer? That's easy. It's visual. You can lay out your various text widgets and other buttons in a neat and clean manner, letting the program handle all the justifications, spacing, etc. Plus, seeing something like a GridLayout in visual action helps make it so much clearer. Using an item like a "stretch" is so much easier to understand when you "see" it in action. Plus, you can revise your layout with ease without affecting your code. Just re-run the "pyuic5" command and you've got a new layout but with all the same logic. Sweet. – Dito Nov 10 '17 at 18:13
  • I did not ask that, but the reason why my solution works, that is to say when you publish a response not only the correction or code must be posted but a justification. :P – eyllanesc Nov 10 '17 at 18:15
  • Oh, sorry. Unclear on the concept. – Dito Nov 10 '17 at 18:54
  • (Got called away in the middle of editing my comment.) Oh, sorry. Unclear on the concept. It works because the object "window" is what initializes the UI, which inherits from QMainWindow, which in turn inherits from QWidget. widget.close() is one of the methods of all widgets. Therefore, window.close() closes the dialog window. – Dito Nov 10 '17 at 19:03

0 Answers0