<tfoot id='MH3oG'></tfoot>

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

        • <bdo id='MH3oG'></bdo><ul id='MH3oG'></ul>
        <legend id='MH3oG'><style id='MH3oG'><dir id='MH3oG'><q id='MH3oG'></q></dir></style></legend>

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

        将焦点放在 QlineEdit 小部件上

        时间:2023-08-05
        • <bdo id='ZbUaZ'></bdo><ul id='ZbUaZ'></ul>
            <tbody id='ZbUaZ'></tbody>
          <tfoot id='ZbUaZ'></tfoot>

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

                • <legend id='ZbUaZ'><style id='ZbUaZ'><dir id='ZbUaZ'><q id='ZbUaZ'></q></dir></style></legend>
                  <i id='ZbUaZ'><tr id='ZbUaZ'><dt id='ZbUaZ'><q id='ZbUaZ'><span id='ZbUaZ'><b id='ZbUaZ'><form id='ZbUaZ'><ins id='ZbUaZ'></ins><ul id='ZbUaZ'></ul><sub id='ZbUaZ'></sub></form><legend id='ZbUaZ'></legend><bdo id='ZbUaZ'><pre id='ZbUaZ'><center id='ZbUaZ'></center></pre></bdo></b><th id='ZbUaZ'></th></span></q></dt></tr></i><div id='ZbUaZ'><tfoot id='ZbUaZ'></tfoot><dl id='ZbUaZ'><fieldset id='ZbUaZ'></fieldset></dl></div>
                • 本文介绍了将焦点放在 QlineEdit 小部件上的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

                  问题描述

                  我正在尝试组合一个简单的小部件,其中焦点自动放在 QLineEdit 小部件上(它用于条形码扫描仪输入,我不希望最终用户必须单击小部件).

                  I am trying to put together a simple widget where the focus is automatically put to a QLineEdit widget (It is for a barcode scanner input, and I don't want the end users to have to click in the widget).

                  相关代码如下:

                  from qtmodern import styles, windows
                  from qtpy import QtGui, QtCore
                  from qtpy.QtWidgets import *
                  from qtpy.QtCore import Qt
                  
                  class MyGui(QWidget):
                      def __init__(self, parent=None):
                          super(MyGui, self).__init__(parent)
                  
                          layout = QVBoxLayout()
                  
                          self.lineEdit = QLineEdit(self)
                          self.lineEdit.setPlaceholderText('foobar')  
                          self.lineEdit.setFocusPolicy(Qt.StrongFocus)      
                          self.lineEdit.setFocus()
                  
                          layout.addWidget(self.lineEdit)
                  
                          self.setLayout(layout)
                          self.show()
                  
                  def main():
                      app = QApplication([])
                      styles.dark(app)
                  
                      g = windows.ModernWindow(MyGui())
                      g.resize(350,100)
                      location = (50, 100)
                      g.move(location[0], location[1])
                      g.setWindowTitle('SmallTest')
                  
                      g.show()
                      app.exec_()
                  
                  if __name__ == '__main__':
                     main()
                  

                  它不想将焦点放在 lineEdit 小部件上.我猜这是我错过的非常明显的东西,但我已经挖了一段时间试图找到它,但还没有偶然发现它.

                  And it doesn't want to put the focus on the lineEdit widget. I'm guessing its something really obvious that I've missed, but I've been digging around for a while trying to find it, and haven't stumbled upon it yet.

                  推荐答案

                  你必须使用 setFocus() 小部件显示后.

                  You must use setFocus() after the widget is displayed.

                  from qtmodern import styles, windows
                  from qtpy import QtGui, QtCore
                  from qtpy.QtWidgets import *
                  from qtpy.QtCore import Qt
                  
                  class MyGui(QWidget):
                      def __init__(self, parent=None):
                          super(MyGui, self).__init__(parent)
                          layout = QVBoxLayout(self)
                          self.lineEdit = QLineEdit(self)
                          self.lineEdit.setPlaceholderText('foobar')  
                          self.lineEdit.setFocusPolicy(Qt.StrongFocus)
                          layout.addWidget(self.lineEdit)
                  
                  def main():
                      app = QApplication([])
                      styles.dark(app)
                      gui = MyGui()
                      g = windows.ModernWindow(gui)
                      g.resize(350,100)
                      location = (50, 100)
                      g.move(*location)
                      g.setWindowTitle('SmallTest')
                      g.show()
                      gui.lineEdit.setFocus()
                      app.exec_()
                  
                  if __name__ == '__main__':
                     main()
                  

                  这篇关于将焦点放在 QlineEdit 小部件上的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持html5模板网!

                  上一篇:如何在标签中显示图片和文本(PyQt) 下一篇:如何编写一个无限循环来接收UDP数据?

                  相关文章

                  最新文章

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

                      <legend id='UHCoc'><style id='UHCoc'><dir id='UHCoc'><q id='UHCoc'></q></dir></style></legend>
                    1. <small id='UHCoc'></small><noframes id='UHCoc'>

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