【问题标题】:QListView with row background in two different colors具有两种不同颜色的行背景的 QListView
【发布时间】:2016-03-15 07:17:17
【问题描述】:

我使用QListView(在 PyQt5 中)来显示字符串。 我想让该列表中每个项目的背景颜色在两种颜色之间变化,以便于阅读。

我尝试了Qt.DecorationRole,但这只会在每个项目的左侧创建一个“图标”。

【问题讨论】:

    标签: python c++ qt pyqt qlistview


    【解决方案1】:

    自我。 listWidget.setAlternatingRowColors(True) 这将为您提供每行的备用颜色。

    【讨论】:

    • 设置颜色不起作用。 palette = QPalette(); palette.setColor(QPalette.AlternateBase, Qt.yellow); self.setPalette(palette); self.setAlternatingRowColors(True)。有什么想法吗?
    • Mhm... 也需要设置QPalette.Base。然后它工作。但我不想明确地设置这个。如何获取当前的QPalette.Base 颜色来设置它。
    猜你喜欢
    • 2021-11-14
    • 2012-02-05
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2022-10-31
    相关资源
    最近更新 更多