PyQt5 - QMessageBox UI

I was trying to make a Popup menu but with a UI that has more than just simple buttons. I need comboboxes and layouts for it too.

So as I was loading QMessageBox and after it use the inherited property from widget, setupUi.

Considering the documentation it should be possible but Krita says QMessageBox does not have the attribute setupUi.

my first attempt was this:

self.ui = QMessageBox()
self.ui.setupUi(self.dir_path + 'file.ui')

Is Message Boxes something that remains locked in the type of UI you can set on it or you can acctually edit the UI for real.

Hi

https://doc.qt.io/qt-5/qwidget.html#setupUi

This function is available with widgets that derive from user interface descriptions created using uic.

The QMessageBox might not be created with uic…

Why just not create a message box from QDialog?

Grum999

1 Like
import PyQt5.uic
from PyQt5.QtCore import (
        pyqtSignal
    )
from PyQt5.QtWidgets import (
        QDialog
    )


class UIDialog(QDialog):

    def __init__(self, uiFile=None, parent=None):
        super(UIDialog, self).__init__(parent)
        if isinstance(uiFile, str):
            PyQt5.uic.loadUi(uiFile, self)


dlg=UIDialog('template.ui')
dlg.show()

Grum999

1 Like

All my searches were pointing for QMessageBox as the way to go. only reason why. And it does work for my needs just the UI falls flat on its face.

I will try that then.

If you wish to add strange widgets to QMenu (QMenuBar menu or context menu),
you can use QwidgetAction

from PyQt5.QtCore import (
        Qt,)

from PyQt5.QtWidgets import (
        QWidget,
        QMainWindow,
        QWidgetAction,
        QCalendarWidget)


class StrangeMenuAction(QWidgetAction):
    def createWidget(self, parent):
        widget = QCalendarWidget(parent=parent)
        return widget


class MyWindow(QMainWindow):
    def __init__(self, parent=None):
        super().__init__(parent)
        self.setObjectName('my_window')
        self.setWindowTitle('My Window')
        self.create_menu()


    def create_menu(self):
        menu_bar = self.menuBar()
        the_menu = menu_bar.addMenu('The Menu')
        strange = StrangeMenuAction(self)
        the_menu.addAction(strange)


win = MyWindow()
win.show()
1 Like

For the dialog I managed to make it work like @Grum999 said after reading tutorials about QDialogs:

# Import Section
from .pigment_o_modulo import (Dialog_UI)
#############################################################

# Boot after the Button Press
self.dialog = Dialog_UI(self)
self.dialog.show()
# Connect Buttons inside Dialog
self.dialog.btn.toggled.connect(self.Menu_RGB)

and for the class in my module secction I tweaked a bit like this:

class Dialog_UI(QDialog):

    def __init__(self, parent):
        super(Dialog_UI, self).__init__(parent)
        # Load UI for Dialog
        self.dir_name = str(os.path.dirname(os.path.realpath(__file__)))
        uic.loadUi(self.dir_name + '/docker.ui', self)

Now the bad thing is not as much related to the code itself but I don’t like the look of my Dialog :sob:
I need to remake a better UI for this situation I think simply

I was reading more about QDialog and it is really nice. wow.
the self.dialog.show() and self.dialog.accept() was what I was looking for all this time.

Dialog_Settings