gpt4 book ai didi

python - 在 PyQt 中设置 QCompleter 弹出窗口的样式

转载 作者:太空狗 更新时间:2023-10-29 21:22:54 27 4
gpt4 key购买 nike

是否可以将样式表应用于绑定(bind)到 QCombobox 的 QCompleter 的弹出部分?如果不是,是否需要委托(delegate)魔法?如果是这样,那怎么可能会起作用,因为它们确实会使我感到困惑。这是我的小部件代码:

class autoFillField(QComboBox):
def __init__(self, parent=None):
super(autoFillField, self).__init__(parent)

self.setFocusPolicy(Qt.NoFocus)
self.setEditable(True)

self.addItem("")

self.pFilterModel = QSortFilterProxyModel(self)
self.pFilterModel.setFilterCaseSensitivity(Qt.CaseInsensitive)
self.pFilterModel.setSourceModel(self.model())

self.completer = QCompleter(self.pFilterModel, self)
self.completer.setCompletionMode(QCompleter.UnfilteredPopupCompletion)
self.setCompleter(self.completer)
self.setStyleSheet(STYLING FOR COMBOBOX HERE, BUT NOT POPUP)

self.lineEdit().textEdited[unicode].connect(self.pFilterModel.setFilterFixedString)

def on_completer_activated(self, text):
if text:
index = self.findText(text)
self.setCurrentIndex(index)

def setModel(self, model):
super(autoFillField, self).setModel(model)
self.pFilterModel.setSourceModel(model)
self.completer.setModel(self.pFilterModel)

def setModelColumn(self, column):
self.completer.setCompletionColumn(column)
self.pFilterModel.setFilterKeyColumn(column)
super(autoFillField, self).setModelColumn(column)

弹出样式会发生在组合框类中,还是发生在通过 addItems 输入数据的外部?提前致谢。

最佳答案

设置 popup of the completer 的样式表,这将是一个 QListView 对象。这是一个可运行的示例(弹出窗口的背景应该是黄色的):

#!/usr/bin/python

import sys
from PyQt4 import QtGui, QtCore

app = QtGui.QApplication(sys.argv)

w = QtGui.QComboBox()
w.setEditable(True)
c = QtGui.QCompleter(['Hello', 'World'])
c.setCompletionMode(QtGui.QCompleter.UnfilteredPopupCompletion)
c.popup().setStyleSheet("background-color: yellow")
w.setCompleter(c)
w.show()

sys.exit(app.exec_())

关于python - 在 PyQt 中设置 QCompleter 弹出窗口的样式,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/8186828/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com