J-Win
J-Win

Reputation: 1492

Using QDialog in QT Designer

I'm pretty new to QT, so I'm not sure what's possible with it yet.

I like using QT Designer for positioning objects in my GUI and doing other basic things. I followed the example at QDialog Tutorial and have it working. However, I was wondering if I could do the same thing in QT Designer such that I could use it to position the dialog box that pops up after clicking the "Hello World" box.

It is possible to position the dialog box in code, but that's not what I'm asking.

Upvotes: 0

Views: 1718

Answers (1)

Vivek Joshy
Vivek Joshy

Reputation: 934

I believe that is not possible with Qt Designer. However, you can always create a QDialog separately and load the .ui file later. You can use the uic.loadUi method for this. This will make all the objects of your dialog available dynamically and save you a lot of development time.

Here is a very short example:

import sys

from PyQt5 import uic
from PyQt5.QtWidgets import QApplication


class WindowLoader:
    """
    All windows and dialogs load here.
    """
    def __init__(self):

        # Your main window.
        self.ui = uic.loadUi("main.ui")
        self.ui.showMaximized()

        # Your custom dialog.
        self.dialog = uic.loadUi("dialog.ui")
        self.dialog.show()

        # Move your dialog later.
        self.dialog.move(50, 50)


app = QApplication(sys.argv)
window = WindowLoader()
sys.exit(app.exec_())

Keep in mind that not all widgets and properties are available to Qt Designer. To the best of my knowledge .move() is not available in Qt Designer. Generally, you would design your .ui file first and call any inaccessible methods from the code to modify properties later.

Upvotes: 3

Related Questions