G
G
GogoL_kie2020-10-15 20:48:41
PyQt
GogoL_kie, 2020-10-15 20:48:41

How to highlight a whole line in PyQt5?

I am writing a music player . I
display a playlist in QTableWidget. Selecting rows with selectRow().
The code that fires on startup to highlight the first row:

self.window.playlist_table.clearSelection()

self.window.playlist_table.setSelectionMode(QAbstractItemView.MultiSelection)

self.window.playlist_table.selectRow(0)

self.window.playlist_table.setSelectionMode(QAbstractItemView.NoSelection)


And here is the code triggered by the cellClicked() event. (click on a cell in the table):
self.window.playlist_table.clearSelection()

self.window.playlist_table.setSelectionMode(QAbstractItemView.MultiSelection)

row_num = self.window.playlist_table.currentRow()
self.window.playlist_table.selectRow(row_num)

self.media_playlist.setCurrentIndex(row_num)
self.playSong()

self.window.playlist_table.setSelectionMode(QAbstractItemView.NoSelection)


And what exactly is the problem. When you start the window, the first line is highlighted in gray, and after clicking - blue. Moreover, if you click on an empty area without cells with a gray selection, the selection will turn blue. It feels like the widget is in a "collapsed" state. How to keep the table always in the "activated" state, or how to select rows correctly?

5f888ae84ff87714347048.png
5f888afe7b83b373436822.png

Answer the question

In order to leave comments, you need to log in

1 answer(s)
P
Pixilys, 2021-05-23
@Pixilys

It 's because of this line
self.window.playlist_table.setSelectionMode(QAbstractItemView.NoSelection)
that "NoSelection" is grayed out.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question