pbootcms网站模板|日韩1区2区|织梦模板||网站源码|日韩1区2区|jquery建站特效-html5模板网

<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="dh9vlxr" 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="tjb3t9v" 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?的處理方法,對大家解決問題具有一定的參考價值,需要的朋友們下面隨著小編來一起學習吧!

                  問題描述

                  在 Qt 5.15 中引入了 placeholderText 屬性 -

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

                  導入系統從 PyQt5 導入 QtWidgets從 PyQt5 導入 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__":應用程序 = 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]"
                  • 操作系統:Ubuntu 20.04.1 LTS(帶 Xfce)

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

                  解決方案

                  查看Qt源碼的修改,發現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;}

                  但這會產生不良影響,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 不再可見的副作用.我已經報告了這個錯誤:QTBUG-90522.

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

                  • 使用 PyQt5/PySide2 5.15.0 或 5.15.1.

                  • 重寫paintEvent方法將placeHolderText設置為currentText:

                  導入系統從 PyQt5 導入 QtCore、QtGui、QtWidgets# 或者# 從 PySide2 導入 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__":應用程序 = 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_()
                  

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

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

                  相關文檔推薦

                  How to bind a function to an Action from Qt menubar?(如何將函數綁定到 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 刻度標簽設置在固定位置,以便當我向左或向右滾動時,yaxis 刻度標簽應該可見
                  `QImage` constructor has unknown keyword `data`(`QImage` 構造函數有未知關鍵字 `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="jtfhdnn" 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>
                            主站蜘蛛池模板: 电动打包机_气动打包机_钢带捆扎机_废纸打包机_手动捆扎机 | 电动不锈钢套筒阀-球面偏置气动钟阀-三通换向阀止回阀-永嘉鸿宇阀门有限公司 | 对辊破碎机-液压双辊式,强力双齿辊,四辊破碎机价格_巩义市金联机械设备生产厂家 | 精密五金加工厂-CNC数控车床加工_冲压件|蜗杆|螺杆加工「新锦泰」 | POS机官网 - 拉卡拉POS机免费办理|官网在线申请入口 | 工业PH计|工业ph酸度计|在线PH计价格-合肥卓尔仪器仪表有限公司 济南画室培训-美术高考培训-山东艺霖艺术培训画室 | 高低温万能试验机_拉力试验机_拉伸试验机-馥勒仪器科技(上海)有限公司 | 客服外包专业服务商_客服外包中心_网萌科技 | 挖掘机挖斗和铲斗生产厂家选择徐州崛起机械制造有限公司 | 锂电叉车,电动叉车_厂家-山东博峻智能科技有限公司 | 管理会计网-PCMA初级管理会计,中级管理会计考试网站 | 北京模型公司-军事模型-工业模型制作-北京百艺模型沙盘公司 | 阀门智能定位器_电液动执行器_气动执行机构-赫尔法流体技术(北京)有限公司 | 一级建造师培训_一建培训机构_中建云筑建造师培训网校 | 圆形振动筛_圆筛_旋振筛_三次元振动筛-河南新乡德诚生产厂家 | 证券新闻,热播美式保罗1984第二部_腾讯1080p-仁爱影院 | 郑州宣传片拍摄-TVC广告片拍摄-微电影短视频制作-河南优柿文化传媒有限公司 | 南京和瑞包装有限公司| 蒜肠网-动漫,二次元,COSPLAY,漫展以及收藏型模型,手办,玩具的新媒体.(原变形金刚变迷TF圈) | 耐火砖厂家,异形耐火砖-山东瑞耐耐火材料厂| 纸布|钩编布|钩针布|纸草布-莱州佳源工艺纸布厂 | led太阳能路灯厂家价格_风光互补庭院灯_农村市政工程路灯-中山华可路灯品牌 | CCC验厂-家用电器|服务器CCC认证咨询-奥测世纪 | 吊篮式|移动式冷热冲击试验箱-二槽冷热冲击试验箱-广东科宝 | 骨密度仪-骨密度测定仪-超声骨密度仪-骨龄测定仪-天津开发区圣鸿医疗器械有限公司 | 危废处理系统,水泥厂DCS集散控制系统,石灰窑设备自动化控制系统-淄博正展工控设备 | 厂厂乐-汇聚海量采购信息的B2B微营销平台-厂厂乐官网 | 定硫仪,量热仪,工业分析仪,马弗炉,煤炭化验设备厂家,煤质化验仪器,焦炭化验设备鹤壁大德煤质工业分析仪,氟氯测定仪 | 二次元影像仪|二次元测量仪|拉力机|全自动影像测量仪厂家_苏州牧象仪器 | PTFE接头|聚四氟乙烯螺丝|阀门|薄膜|消解罐|聚四氟乙烯球-嘉兴市方圆氟塑制品有限公司 | 蓄电池回收,ups电池后备电源回收,铅酸蓄电池回收,机房电源回收-广州益夫铅酸电池回收公司 | 培训无忧网-教育培训咨询招生第三方平台 | 南京试剂|化学试剂|分析试剂|实验试剂|cas号查询-专业60年试剂销售企业 | 安驭邦官网-双向万能直角铣头,加工中心侧铣头,角度头[厂家直销] 闸阀_截止阀_止回阀「生产厂家」-上海卡比阀门有限公司 | 广州中央空调回收,二手中央空调回收,旧空调回收,制冷设备回收,冷气机组回收公司-广州益夫制冷设备回收公司 | 耐腐蚀泵,耐腐蚀真空泵,玻璃钢真空泵-淄博华舜耐腐蚀真空泵有限公司 | RS系列电阻器,RK_RJ启动调整电阻器,RQ_RZ电阻器-上海永上电器有限公司 | 气动|电动调节阀|球阀|蝶阀-自力式调节阀-上海渠工阀门管道工程有限公司 | 丹佛斯压力传感器,WISE温度传感器,WISE压力开关,丹佛斯温度开关-上海力笙工业设备有限公司 | 蓝莓施肥机,智能施肥机,自动施肥机,水肥一体化项目,水肥一体机厂家,小型施肥机,圣大节水,滴灌施工方案,山东圣大节水科技有限公司官网17864474793 | 成都LED显示屏丨室内户外全彩led屏厂家方案报价_四川诺显科技 |