简体   繁体   中英

Is it possible to highlight (not select) multiple rows in QListWidget?? (Python/PyQt)

我想知道是否有可能在QListWidget 突出显示多行(而不是setSelectedRow或选择多行)...如果是的话,我将如何去做?

There are many ways to highlight the items in a listWidget. You can set the background color, foreground color or completely change the font of the items to be highlighted.

Set the foreground:

for item in listWidget.selectedItems():
    item.setForeground(QBrush(Qt.green, Qt.SolidPattern))

Set the background:

for item in listWidget.selectedItems():
    item.setBackground(QBrush(Qt.yellow, Qt.SolidPattern))

Or change the font of the items:

font = QFont('', -1, QFont.Bold, True)
for item in listWidget.selectedItems():
    item.setFont(font)

Empty string to QFont means default font family, -1 means default font size, finally made the font bold and made it italic by setting the last parameter to True. If you don't want bold font, pass -1 instead of QFont.Bold

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM