在我的节目中,
QLineEdit 和 QListWidget 放置在 QVBoxLayout 中。然后 QVBoxLayout 放入一个带有背景颜色样式表的 QFrame:橙色。
QLineEdit 和 QListWidget 也获得与 QFrame 相同的背景颜色。如何避免背景颜色重叠?.
假设,如果我们通过样式表改变QListwidget的背景颜色,那么滚动条颜色也改变为QListWidget颜色。
如何避免?,我需要原生样式布局?
import sys
from PyQt5.QtCore import *
from PyQt5.QtGui import *
from PyQt5.QtWidgets import *
item = ["Python", "Python 2.7", "Python 2.9", "Python 3.5", "Python 3.7", "National", "Zebra",
"Apple", "X Ray","Boat", "Tiger", "Item001", "Item002", "Item003", "Item004", "Item005",
"001Item", "002Item", "003Item","004Item", "005Item", "Ball", "Cat", "Dog", "Fish",
"Gold Fish", "Star Fish"]
class myList(QWidget):
def __init__(self):
super().__init__()
self.setWindowTitle("Frame Example")
self.myui()
def myui(self):
self.textbox = QLineEdit(self)
self.listbox = QListWidget(self)
self.listbox.addItems(item)
vbox = QVBoxLayout()
vbox.addWidget(self.textbox)
vbox.addWidget(self.listbox)
frame = QFrame()
frame.setLayout(vbox)
frame.setStyleSheet("background-color:orange")
main_layout =QHBoxLayout()
main_layout.addWidget(frame)
self.setLayout(main_layout)
def main():
myapp = QApplication(sys.argv)
mywin = myList()
mywin.show()
sys.exit(myapp.exec_())
if __name__ == '__main__':
main()