Python 如何设计QComboBox弹出式材料的样式?
我想用PySide创建一个材质样式的应用程序。Python 如何设计QComboBox弹出式材料的样式?,python,pyside,qcombobox,Python,Pyside,Qcombobox,我想用PySide创建一个材质样式的应用程序。 我正在尝试使QComboBox看起来像下面的屏幕: 我现在坚持使用showPopup()函数,不知道如何重新实现它。 一些提示会很好。 from PySide import QtGui, QtCore import sys class MyComboBox(QtGui.QComboBox): def __init__(self, *args, **kwargs): QtGui.QComboBox.__init__(sel
我正在尝试使QComboBox看起来像下面的屏幕:
我现在坚持使用showPopup()函数,不知道如何重新实现它。 一些提示会很好。
from PySide import QtGui, QtCore
import sys
class MyComboBox(QtGui.QComboBox):
def __init__(self, *args, **kwargs):
QtGui.QComboBox.__init__(self, *args, **kwargs)
self.grey = QtGui.QColor(115,115,115)
self.line = QtGui.QColor(210,210,210)
# def mousePressEvent(self, *args, **kwargs):
# pass
def paintEvent(self, Event):
self.setMinimumHeight(25)
self.setMinimumWidth(40)
self.setMaximumHeight(40)
self.setMaximumWidth(120)
offset = self.width() - 12-14
font = QtGui.QFont()
font.setPixelSize(12)
font.setFamily('Arial')
self.resize(self.parent().width(), self.parent().height())
painter = QtGui.QPainter()
painter.begin(self)
brush = QtGui.QBrush(QtGui.QColor(238, 238, 238), style=QtCore.Qt.SolidPattern)
painter.fillRect(self.rect(), brush)
painter.setRenderHint(QtGui.QPainter.Antialiasing)
brush = QtGui.QBrush(self.line, style=QtCore.Qt.SolidPattern)
painter.setBrush(brush)
painter.setPen(QtGui.QColor(119, 194, 187, 0))
painter.drawRoundedRect(10, self.height()-1, self.width(), 1, 0, 0)
brush = QtGui.QBrush(self.grey, style=QtCore.Qt.SolidPattern)
painter.setBrush(brush)
poly = QtGui.QPolygon([QtCore.QPoint(offset, 18), QtCore.QPoint(offset + 12, 18), QtCore.QPoint(6 + offset, 25), QtCore.QPoint(offset, 18)])
painter.drawConvexPolygon(poly)
painter.setFont(font)
painter.setPen(QtGui.QColor(0, 0, 0))
painter.drawText(20, 27, self.currentText())
def showPopup(self):
QtGui.QComboBox.showPopup(self)
if __name__ == '__main__':
app = QtGui.QApplication(sys.argv)
widget = QtGui.QWidget()
widget.setStyleSheet("background-color: rgb(238, 238, 238);\n")
grid = QtGui.QGridLayout()
combo = MyComboBox()
combo.setParent(widget)
for strItem in ['Hello', 'World']:
combo.addItem(strItem)
grid.addWidget(combo, 0, 0)
widget.setLayout(grid)
widget.resize(200, 300)
widget.show()
combo.show()
sys.exit(app.exec_())
你能在这里添加一些代码吗?好的,我喜欢制作一个QSCROLAREA小部件,这是正确的方法吗?你能在这里添加一些代码吗?好的,我喜欢制作一个QSCROLAREA小部件,这是正确的方法吗?