<bdo id='75zwp'></bdo><ul id='75zwp'></ul>
      1. <tfoot id='75zwp'></tfoot>

        <small id='75zwp'></small><noframes id='75zwp'>

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

        <legend id='75zwp'><style id='75zwp'><dir id='75zwp'><q id='75zwp'></q></dir></style></legend>

        如何显示 PyQt 模式对话框并在关闭后从其控件中获取数据?

        时间:2023-06-05
          <tbody id='YOyZq'></tbody>
          <i id='YOyZq'><tr id='YOyZq'><dt id='YOyZq'><q id='YOyZq'><span id='YOyZq'><b id='YOyZq'><form id='YOyZq'><ins id='YOyZq'></ins><ul id='YOyZq'></ul><sub id='YOyZq'></sub></form><legend id='YOyZq'></legend><bdo id='YOyZq'><pre id='YOyZq'><center id='YOyZq'></center></pre></bdo></b><th id='YOyZq'></th></span></q></dt></tr></i><div id='YOyZq'><tfoot id='YOyZq'></tfoot><dl id='YOyZq'><fieldset id='YOyZq'></fieldset></dl></div>

        1. <legend id='YOyZq'><style id='YOyZq'><dir id='YOyZq'><q id='YOyZq'></q></dir></style></legend>

              <bdo id='YOyZq'></bdo><ul id='YOyZq'></ul>
              <tfoot id='YOyZq'></tfoot>

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

                1. 本文介绍了如何显示 PyQt 模式对话框并在关闭后从其控件中获取数据?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着跟版网的小编来一起学习吧!

                  问题描述

                  对于像 QInputDialog 这样的内置对话框,我读到我可以这样做:

                  For a built-in dialog like QInputDialog, I've read that I can do this:

                  text, ok = QtGui.QInputDialog.getText(self, 'Input Dialog', 'Enter your name:')
                  

                  如何使用我在 Qt Designer 中自己设计的对话框来模拟这种行为?例如,我想做:

                  How can I emulate this behavior using a dialog that I design myself in Qt Designer? For instance, I would like to do:

                  my_date, my_time, ok = MyCustomDateTimeDialog.get_date_time(self)
                  

                  推荐答案

                  这是一个简单的类,你可以用它来提示日期:

                  Here is simple class you can use to prompt for date:

                  class DateDialog(QDialog):
                      def __init__(self, parent = None):
                          super(DateDialog, self).__init__(parent)
                  
                          layout = QVBoxLayout(self)
                  
                          # nice widget for editing the date
                          self.datetime = QDateTimeEdit(self)
                          self.datetime.setCalendarPopup(True)
                          self.datetime.setDateTime(QDateTime.currentDateTime())
                          layout.addWidget(self.datetime)
                  
                          # OK and Cancel buttons
                          buttons = QDialogButtonBox(
                              QDialogButtonBox.Ok | QDialogButtonBox.Cancel,
                              Qt.Horizontal, self)
                          buttons.accepted.connect(self.accept)
                          buttons.rejected.connect(self.reject)
                          layout.addWidget(buttons)
                  
                      # get current date and time from the dialog
                      def dateTime(self):
                          return self.datetime.dateTime()
                  
                      # static method to create the dialog and return (date, time, accepted)
                      @staticmethod
                      def getDateTime(parent = None):
                          dialog = DateDialog(parent)
                          result = dialog.exec_()
                          date = dialog.dateTime()
                          return (date.date(), date.time(), result == QDialog.Accepted)
                  

                  并使用它:

                  date, time, ok = DateDialog.getDateTime()
                  

                  这篇关于如何显示 PyQt 模式对话框并在关闭后从其控件中获取数据?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

                  上一篇:如何使用 asksaveasfile 将文本从 Text-widget Tkinter 保存到 .doc? 下一篇:如何将对话框窗口中的选定文件添加到字典中?

                  相关文章

                  <tfoot id='pY6m2'></tfoot>
                  1. <small id='pY6m2'></small><noframes id='pY6m2'>

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

                        <bdo id='pY6m2'></bdo><ul id='pY6m2'></ul>