0

I'm trying to adapt a windows 10 python program to Linux: I use QListWidget in this program which is resizable But in Linux the height of a row is bigger.

I use setSpacing with a negative value to accomodate but it overlaps a bit

self.my_playlist = QListWidget(self.bgList)
self.my_playlist.setGeometry(7, 6, 276, 310)
self.my_playlist.setSpacing(-2)

enter image description here

I'm wondering if there is a way to reduce internal spacing

  • Have a look at this answer: https://stackoverflow.com/a/49422408/21974 You could try to manipulate the margin instead of padding (spacing). If I were you I wouldn't try to mess with the basic layout / ui theme. The theme is also individual, on Linux there is many themes to install and choose from. – ypnos Feb 20 '22 at 20:46
  • thank you that what i'm looking for, the result is approximative but it works – sebastien deepwali Feb 20 '22 at 21:09
  • Using the spacing for such requirements is not a good choice, as it might cause unexpected results. The correct way to ensure that items are well spaced and, most importantly, their content properly shown, is to use an item delegate that returns the appropriate size hint. Besides, that `setGeometry()` is there just because of Designer, right? You *are* using layout managers, aren't you? – musicamante Feb 20 '22 at 21:32
  • Thank you, i was wondering how to retrieve the height of one line, to adjust the heigth of the list proportionnaly. I don't know how to do find it. The setGeometry is here to adjust the heigth to exact number of items in the list. I don't what is a layout manager, i design all the app with code and the wndow resize when you add an item to the list – sebastien deepwali Feb 22 '22 at 12:26
  • ok if found the sizeHint function, i will try. Forza Italia :) – sebastien deepwali Feb 22 '22 at 12:37
  • I use sizehint to get the height self.my_playlist.sizeHint().height() but it always return 192px even if i add more items in the list i don't understand – sebastien deepwali Feb 22 '22 at 14:00
  • I tried self.my_playlist.size().height() before setGeo but now its 30px ??? the heigth is something like 22px for one line ... there is no way to overide QT style ? – sebastien deepwali Feb 22 '22 at 14:07
  • I found .sizeHintForRow(0) which give me i think the good size of a row – sebastien deepwali Feb 27 '22 at 22:08

0 Answers0