Y
Y
yong2019-04-15 10:59:18
Python
yong, 2019-04-15 10:59:18

How to make QMainWindow close by button on QDockWidget?

Good day. It is necessary to add the closing of the main window by the QPushButton button. I can't find any information on how to do this. Here is part of my code

class MainWindow(QMainWindow):
    def __init__(self, *args, **kwargs):
        super(MainWindow, self).__init__(*args, **kwargs)

        self.browser = QWebEngineView()
        self.browser.setUrl(QUrl("http://yandex.ru"))

        self.browser.urlChanged.connect(self.update_urlbar)
        self.browser.loadFinished.connect(self.update_title)
        self.setCentralWidget(self.browser)

        self.status = QStatusBar()
        self.setStatusBar(self.status)

## QDockWidget ##
        self.docked = QDockWidget("Виджет", self)
        self.addDockWidget(Qt.LeftDockWidgetArea, self.docked)
        self.dockedWidget = QWidget(self)
        self.docked.setWidget(self.dockedWidget)
        self.dockedWidget.setLayout(QVBoxLayout())
        self.dockedWidget.layout().addWidget(QPushButton('Завершить работу'))

The button is created on the panel, but how can I add it so that the window closes on click? I turned off the standard cross, this option is needed. Help who can)

Answer the question

In order to leave comments, you need to log in

1 answer(s)
V
Vitaly, 2019-04-15
@yong

self.closeBtn = QPushButton(self.tr('Close'))
self.closeBtn.clicked.connect(self.close)
self.dockedWidget.layout().addWidget(self.closeBtn)

Here is the documentation:
https://doc.qt.io/qt-5/qwidget.html#close
https://doc.qt.io/qt-5/qabstractbutton.html#clicked
Well, there are also docks on pyside itself. Although, you can just look at Qt. pyside is just bindings after all.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question