<i id='1XUnw'><tr id='1XUnw'><dt id='1XUnw'><q id='1XUnw'><span id='1XUnw'><b id='1XUnw'><form id='1XUnw'><ins id='1XUnw'></ins><ul id='1XUnw'></ul><sub id='1XUnw'></sub></form><legend id='1XUnw'></legend><bdo id='1XUnw'><pre id='1XUnw'><center id='1XUnw'></center></pre></bdo></b><th id='1XUnw'></th></span></q></dt></tr></i><div id='1XUnw'><tfoot id='1XUnw'></tfoot><dl id='1XUnw'><fieldset id='1XUnw'></fieldset></dl></div>
  • <small id='1XUnw'></small><noframes id='1XUnw'>

        <tfoot id='1XUnw'></tfoot>
          <bdo id='1XUnw'></bdo><ul id='1XUnw'></ul>
      1. <legend id='1XUnw'><style id='1XUnw'><dir id='1XUnw'><q id='1XUnw'></q></dir></style></legend>

        检测 Widget-window resized 信号中的调整大小

        时间:2023-08-05

          <small id='a0yDh'></small><noframes id='a0yDh'>

            <tfoot id='a0yDh'></tfoot>
            <i id='a0yDh'><tr id='a0yDh'><dt id='a0yDh'><q id='a0yDh'><span id='a0yDh'><b id='a0yDh'><form id='a0yDh'><ins id='a0yDh'></ins><ul id='a0yDh'></ul><sub id='a0yDh'></sub></form><legend id='a0yDh'></legend><bdo id='a0yDh'><pre id='a0yDh'><center id='a0yDh'></center></pre></bdo></b><th id='a0yDh'></th></span></q></dt></tr></i><div id='a0yDh'><tfoot id='a0yDh'></tfoot><dl id='a0yDh'><fieldset id='a0yDh'></fieldset></dl></div>
            <legend id='a0yDh'><style id='a0yDh'><dir id='a0yDh'><q id='a0yDh'></q></dir></style></legend>

              <tbody id='a0yDh'></tbody>

                  <bdo id='a0yDh'></bdo><ul id='a0yDh'></ul>
                • 本文介绍了检测 Widget-window resized 信号中的调整大小的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

                  问题描述

                  我使用 Qt Designer 创建了一个简单的 UI,并将其转换为 Python 代码.我搜索了任何方法来检测窗口大小的变化.

                  I create a simple UI with Qt Designer and convert it to Python codes. I searched for any method to detect changing window size.

                  这是生成的代码:

                  from PyQt5 import QtCore, QtGui, QtWidgets
                  
                  class Ui_MainWindow(object):
                      def onResize(event):
                          print(event)
                  
                      def setupUi(self, MainWindow):
                          MainWindow.setObjectName("MainWindow")
                          MainWindow.setWindowTitle("MainWindow")
                          MainWindow.resize(200, 200)
                          self.centralwidget = QtWidgets.QWidget(MainWindow)
                          self.centralwidget.setObjectName("centralwidget")
                          MainWindow.setCentralWidget(self.centralwidget)
                  
                          MainWindow.resized.connect(self.someFunction)
                  
                          QtCore.QMetaObject.connectSlotsByName(MainWindow)
                  
                  if __name__ == "__main__":
                      import sys
                      app = QtWidgets.QApplication(sys.argv)
                      MainWindow = QtWidgets.QMainWindow()
                      ui = Ui_MainWindow()
                      ui.setupUi(MainWindow)
                      MainWindow.show()
                      sys.exit(app.exec_())
                  

                  我发现了一个类似的问题QWidget resize signal?和本教程处理大小 建议覆盖 resizeEvent 方法QMainWindow.

                  I found a similar question QWidget resize signal? and this tutorial to handle size that recommended overriding resizeEvent method of QMainWindow.

                  但其中任何一个都不能解决我的问题.是否有任何 resized 函数来检测窗口调整大小,如下所示:

                  But any of them doesn't solve my problem. Is there any resized function to detect window resizing like below:

                  MainWindow.resized.connect(self.someFunction)
                  

                  推荐答案

                  默认没有这个信号,但是你可以创建resized信号,我们在resizeEvent 函数.

                  There is no such signal by default, but you can create the resized signal, we emit it in the resizeEvent function.

                  例如:

                  from PyQt5 import QtCore, QtGui, QtWidgets
                  
                  class Ui_MainWindow(object):
                      def setupUi(self, MainWindow):
                          MainWindow.setObjectName("MainWindow")
                          MainWindow.setWindowTitle("MainWindow")
                          MainWindow.resize(200, 200)
                          self.centralwidget = QtWidgets.QWidget(MainWindow)
                          self.centralwidget.setObjectName("centralwidget")
                          MainWindow.setCentralWidget(self.centralwidget)
                          QtCore.QMetaObject.connectSlotsByName(MainWindow)
                  
                  
                  class Window(QtWidgets.QMainWindow):
                      resized = QtCore.pyqtSignal()
                      def  __init__(self, parent=None):
                          super(Window, self).__init__(parent=parent)
                          ui = Ui_MainWindow()
                          ui.setupUi(self)
                          self.resized.connect(self.someFunction)
                  
                      def resizeEvent(self, event):
                          self.resized.emit()
                          return super(Window, self).resizeEvent(event)
                  
                      def someFunction(self):
                          print("someFunction")
                  
                  
                  if __name__ == "__main__":
                      import sys
                      app = QtWidgets.QApplication(sys.argv)
                      w = Window()
                      w.show()
                      sys.exit(app.exec_())
                  

                  这篇关于检测 Widget-window resized 信号中的调整大小的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持html5模板网!

                  上一篇:pyqt5 tabwidget 垂直制表符 水平文本左对齐 下一篇:如何在 QWidget 中的 matplot 画布上跟踪鼠标?

                  相关文章

                  最新文章

                  <tfoot id='7okw3'></tfoot>
                • <i id='7okw3'><tr id='7okw3'><dt id='7okw3'><q id='7okw3'><span id='7okw3'><b id='7okw3'><form id='7okw3'><ins id='7okw3'></ins><ul id='7okw3'></ul><sub id='7okw3'></sub></form><legend id='7okw3'></legend><bdo id='7okw3'><pre id='7okw3'><center id='7okw3'></center></pre></bdo></b><th id='7okw3'></th></span></q></dt></tr></i><div id='7okw3'><tfoot id='7okw3'></tfoot><dl id='7okw3'><fieldset id='7okw3'></fieldset></dl></div>
                  <legend id='7okw3'><style id='7okw3'><dir id='7okw3'><q id='7okw3'></q></dir></style></legend>

                      • <bdo id='7okw3'></bdo><ul id='7okw3'></ul>

                      <small id='7okw3'></small><noframes id='7okw3'>