久久久久久久av_日韩在线中文_看一级毛片视频_日本精品二区_成人深夜福利视频_武道仙尊动漫在线观看

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

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

      <legend id='A0Jxe'><style id='A0Jxe'><dir id='A0Jxe'><q id='A0Jxe'></q></dir></style></legend>
      • <bdo id='A0Jxe'></bdo><ul id='A0Jxe'></ul>
      1. 如何使用 QComboBox.setPlaceholderText?

        How do i use QComboBox.setPlaceholderText?(如何使用 QComboBox.setPlaceholderText?)

      2. <tfoot id='CyGL0'></tfoot>

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

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

                  本文介紹了如何使用 QComboBox.setPlaceholderText?的處理方法,對大家解決問題具有一定的參考價值,需要的朋友們下面隨著小編來一起學(xué)習(xí)吧!

                  問題描述

                  在 Qt 5.15 中引入了 placeholderText 屬性 -

                  這是一個錯誤還是我錯過了什么?我怎樣才能做到這一點?

                  導(dǎo)入系統(tǒng)從 PyQt5 導(dǎo)入 QtWidgets從 PyQt5 導(dǎo)入 QtCore類 MainWindow(QtWidgets.QMainWindow):def __init__(self):超級().__init__()central_w = QtWidgets.QWidget()self.setCentralWidget(central_w)vbox = QtWidgets.QVBoxLayout()central_w.setLayout(vbox)self.combo_box = QtWidgets.QComboBox()self.combo_box.addItems([一"、二"、三"])self.combo_box.setPlaceholderText("這里有一些占位符文本")self.combo_box.setCurrentIndex(-1)vbox.addWidget(self.combo_box)如果 __name__ == __main__":應(yīng)用程序 = QtWidgets.QApplication(sys.argv)主窗口 = 主窗口()main_window.show()app.exec_()

                  我沒有找到顯示占位符文本的方法.我試過在組合框中根本沒有項目,但即使這樣也不顯示占位符文本


                  這些是我正在運行的版本:

                  • Qt:5.15.2
                  • PyQt(Python 模塊)版本:5.15.2(這恰好與 Qt 版本相同,但有時可能略有不同)
                  • Python:3.8.5(默認,2020 年 7 月 28 日,12:59:40) [GCC 9.3.0]"
                  • 操作系統(tǒng):Ubuntu 20.04.1 LTS(帶 Xfce)

                  PS:如果你想達到類似的效果(即:在可點擊區(qū)域上有一個文本,點擊后顯示帶有不同選項的下拉菜單)你可以使用 QPushButtonsetMenu 函數(shù).文檔:https://doc.qt.io/qt-5/qpushbutton.html#setMenu

                  解決方案

                  查看Qt源碼的修改,發(fā)現(xiàn)Qt 5.15.0增加placeHolderText的功能,修改了currentText():

                  //https://code.qt.io/cgit/qt/qtbase.git/tree/src/widgets/widgets/qcombobox.cpp?h=5.15.0#n2344QString QComboBox::currentText() 常量{Q_D(const QComboBox);if (d->lineEdit)return d->lineEdit->text();else if (d->currentIndex.isValid())返回 d->itemText(d->currentIndex);別的return d->placeholderText;}

                  但這會產(chǎn)生不良影響,QTBUG-86580在 Qt 5.15.2 中被刪除:

                  QString QComboBox::currentText() const{Q_D(const QComboBox);if (d->lineEdit)return d->lineEdit->text();if (d->currentIndex.isValid())返回 d->itemText(d->currentIndex);返回 {};}

                  忘記糾正 placeHolder 不再可見的副作用.我已經(jīng)報告了這個錯誤:QTBUG-90522.

                  考慮到上述情況,有以下備選方案:

                  • 使用 PyQt5/PySide2 5.15.0 或 5.15.1.

                  • 重寫paintEvent方法將placeHolderText設(shè)置為currentText:

                  導(dǎo)入系統(tǒng)從 PyQt5 導(dǎo)入 QtCore、QtGui、QtWidgets# 或者# 從 PySide2 導(dǎo)入 QtCore、QtGui、QtWidgets類組合框(QtWidgets.QComboBox):# https://code.qt.io/cgit/qt/qtbase.git/tree/src/widgets/widgets/qcombobox.cpp?h=5.15.2#n3173defpaintEvent(自我,事件):畫家 = QtWidgets.QStylePainter(self)Painter.setPen(self.palette().color(QtGui.QPalette.Text))# 繪制組合框框、focusrect 和 selected 等.opt = QtWidgets.QStyleOptionComboBox()self.initStyleOption(opt)Painter.drawComplexControl(QtWidgets.QStyle.CC_ComboBox,選擇)如果 self.currentIndex() <0:opt.palette.setBrush(QtGui.QPalette.ButtonText,opt.palette.brush(QtGui.QPalette.ButtonText).color().lighter(),)如果 self.placeholderText():opt.currentText = self.placeholderText()# 繪制圖標和文本Painter.drawControl(QtWidgets.QStyle.CE_ComboBoxLabel,選擇)類 MainWindow(QtWidgets.QMainWindow):def __init__(self):超級().__init__()self.combo_box = 組合框()self.combo_box.addItems([一"、二"、三"])self.combo_box.setPlaceholderText("這里有一些占位符文本")self.combo_box.setCurrentIndex(-1)central_w = QtWidgets.QWidget()self.setCentralWidget(central_w)vbox = QtWidgets.QVBoxLayout(central_w)vbox.addWidget(self.combo_box)如果 __name__ == __main__":應(yīng)用程序 = QtWidgets.QApplication(sys.argv)主窗口 = 主窗口()main_window.show()app.exec_()

                  In Qt 5.15 the placeholderText property was introduced - link to documentation

                  However using setPlaceholderText doesn't do anything for me. When running the code below i don't get any text in the QComboBox (unless of course i select one of the three items)

                  Is this a bug or am i missing something? How can i make this work?

                  import sys
                  from PyQt5 import QtWidgets
                  from PyQt5 import QtCore
                  
                  
                  class MainWindow(QtWidgets.QMainWindow):
                      def __init__(self):
                          super().__init__()
                  
                          central_w = QtWidgets.QWidget()
                          self.setCentralWidget(central_w)
                          vbox = QtWidgets.QVBoxLayout()
                          central_w.setLayout(vbox)
                  
                          self.combo_box = QtWidgets.QComboBox()
                          self.combo_box.addItems(["one", "two", "three"])
                          self.combo_box.setPlaceholderText("Some placeholder text here")
                          self.combo_box.setCurrentIndex(-1)
                          vbox.addWidget(self.combo_box)
                  
                  
                  if __name__ == "__main__":
                      app = QtWidgets.QApplication(sys.argv)
                      main_window = MainWindow()
                      main_window.show()
                      app.exec_()
                  

                  I have found no way of showing the placeholder text. I've tried having no items at all in the combo box but even this doesn't show the placeholder text


                  These are the versions i am running:

                  • Qt: 5.15.2
                  • PyQt (Python module) version: 5.15.2 (this happens to be the same as the Qt version but can sometimes differ slightly)
                  • Python: "3.8.5 (default, Jul 28 2020, 12:59:40) [GCC 9.3.0]"
                  • OS: Ubuntu 20.04.1 LTS (with Xfce)

                  PS: If you want to achieve a similar effect (that is: having a text on a clickable area which shows a drop-down with different options after being clicked) you can use a QPushButton with the setMenu function. Documentation: https://doc.qt.io/qt-5/qpushbutton.html#setMenu

                  解決方案

                  Reviewing the modifications of the Qt source code, it is observed that to add the functionality of the placeHolderText in Qt 5.15.0, the currentText() was modified:

                  // https://code.qt.io/cgit/qt/qtbase.git/tree/src/widgets/widgets/qcombobox.cpp?h=5.15.0#n2344
                  QString QComboBox::currentText() const
                  {
                      Q_D(const QComboBox);
                      if (d->lineEdit)
                          return d->lineEdit->text();
                      else if (d->currentIndex.isValid())
                          return d->itemText(d->currentIndex);
                      else
                          return d->placeholderText;
                  }
                  

                  But that generates an undesirable effect that was reported in QTBUG-86580 so that functionality was removed in Qt 5.15.2:

                  QString QComboBox::currentText() const
                  {
                      Q_D(const QComboBox);
                      if (d->lineEdit)
                          return d->lineEdit->text();
                      if (d->currentIndex.isValid())
                          return d->itemText(d->currentIndex);
                      return {};
                  }
                  

                  Forgetting to correct the side effect which is that the placeHolder is no longer visible. I have already reported the bug: QTBUG-90522.

                  Considering the above, there are the following alternatives:

                  • Use PyQt5/PySide2 5.15.0 or 5.15.1.

                  • Override the paintEvent method to set the placeHolderText as currentText:

                  import sys
                  from PyQt5 import QtCore, QtGui, QtWidgets
                  
                  # or
                  # from PySide2 import QtCore, QtGui, QtWidgets
                  
                  
                  class ComboBox(QtWidgets.QComboBox):
                      # https://code.qt.io/cgit/qt/qtbase.git/tree/src/widgets/widgets/qcombobox.cpp?h=5.15.2#n3173
                      def paintEvent(self, event):
                          
                          painter = QtWidgets.QStylePainter(self)
                          painter.setPen(self.palette().color(QtGui.QPalette.Text))
                  
                          # draw the combobox frame, focusrect and selected etc.
                          opt = QtWidgets.QStyleOptionComboBox()
                          self.initStyleOption(opt)
                          painter.drawComplexControl(QtWidgets.QStyle.CC_ComboBox, opt)
                  
                          if self.currentIndex() < 0:
                              opt.palette.setBrush(
                                  QtGui.QPalette.ButtonText,
                                  opt.palette.brush(QtGui.QPalette.ButtonText).color().lighter(),
                              )
                              if self.placeholderText():
                                  opt.currentText = self.placeholderText()
                  
                          # draw the icon and text
                          painter.drawControl(QtWidgets.QStyle.CE_ComboBoxLabel, opt)
                  
                  
                  class MainWindow(QtWidgets.QMainWindow):
                      def __init__(self):
                          super().__init__()
                  
                          self.combo_box = ComboBox()
                          self.combo_box.addItems(["one", "two", "three"])
                          self.combo_box.setPlaceholderText("Some placeholder text here")
                          self.combo_box.setCurrentIndex(-1)
                  
                          central_w = QtWidgets.QWidget()
                          self.setCentralWidget(central_w)
                          vbox = QtWidgets.QVBoxLayout(central_w)
                          vbox.addWidget(self.combo_box)
                  
                  
                  if __name__ == "__main__":
                      app = QtWidgets.QApplication(sys.argv)
                      main_window = MainWindow()
                      main_window.show()
                      app.exec_()
                  

                  這篇關(guān)于如何使用 QComboBox.setPlaceholderText?的文章就介紹到這了,希望我們推薦的答案對大家有所幫助,也希望大家多多支持html5模板網(wǎng)!

                  【網(wǎng)站聲明】本站部分內(nèi)容來源于互聯(lián)網(wǎng),旨在幫助大家更快的解決問題,如果有圖片或者內(nèi)容侵犯了您的權(quán)益,請聯(lián)系我們刪除處理,感謝您的支持!

                  相關(guān)文檔推薦

                  How to bind a function to an Action from Qt menubar?(如何將函數(shù)綁定到 Qt 菜單欄中的操作?)
                  PyQt progress jumps to 100% after it starts(PyQt 啟動后進度躍升至 100%)
                  How to set yaxis tick label in a fixed position so that when i scroll left or right the yaxis tick label should be visible?(如何將 yaxis 刻度標簽設(shè)置在固定位置,以便當我向左或向右滾動時,yaxis 刻度標簽應(yīng)該可見
                  `QImage` constructor has unknown keyword `data`(`QImage` 構(gòu)造函數(shù)有未知關(guān)鍵字 `data`)
                  Change x-axis ticks to custom strings(將 x 軸刻度更改為自定義字符串)
                  How to show progress bar while saving file to excel in python?(如何在python中將文件保存為excel時顯示進度條?)

                      <tbody id='RuToi'></tbody>

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

                      • <tfoot id='RuToi'></tfoot>
                        • <bdo id='RuToi'></bdo><ul id='RuToi'></ul>

                          <i id='RuToi'><tr id='RuToi'><dt id='RuToi'><q id='RuToi'><span id='RuToi'><b id='RuToi'><form id='RuToi'><ins id='RuToi'></ins><ul id='RuToi'></ul><sub id='RuToi'></sub></form><legend id='RuToi'></legend><bdo id='RuToi'><pre id='RuToi'><center id='RuToi'></center></pre></bdo></b><th id='RuToi'></th></span></q></dt></tr></i><div class="qwawimqqmiuu" id='RuToi'><tfoot id='RuToi'></tfoot><dl id='RuToi'><fieldset id='RuToi'></fieldset></dl></div>
                          <legend id='RuToi'><style id='RuToi'><dir id='RuToi'><q id='RuToi'></q></dir></style></legend>
                            主站蜘蛛池模板: 国产精品一区一区三区 | 国产精品一区二区在线免费观看 | 2019天天操 | av片免费| 久久久久国产精品一区二区 | 免费黄色的视频 | 激情在线视频 | 91视频在线 | 午夜理伦三级理论三级在线观看 | 久久国产亚洲 | 久久丁香 | 国产高清久久久 | 成人国产精品一级毛片视频毛片 | 一级毛片中国 | 激情五月婷婷综合 | 一区二区三区视频在线免费观看 | av香蕉 | 欧美久久一区二区 | 国产精品a免费一区久久电影 | 亚洲麻豆 | 日韩色图视频 | 亚洲精品久久 | 国产精品久久久99 | 三级免费 | 中文字幕第十五页 | 久久久久久久久久久久久9999 | 国产线视频精品免费观看视频 | 亚洲综合五月天婷婷 | 日韩有码在线观看 | 中文字幕高清免费日韩视频在线 | 欧美精品一区二区三区在线 | 国产精品毛片 | 97国产爽爽爽久久久 | 日本精品视频一区二区 | 免费国产一区二区视频 | 毛片免费观看 | 天天久久| 国产一区二区三区在线免费观看 | 91国产精品 | 成人久久18免费 | 亚洲视频中文字幕 |