Program is for linux distributions.
I am trying to notify user when something is wrong with the item in the list when it is double clicked.
I used setStyleSheet, only to find out that it does not work on unity and cinnamon, while it works on KDE and i3.

I am not all that savvy with qbrushes or some other stuff I am googling out.
So whats the best way to solve this, so that it works everywhere? Thanks.

Heres a gif of my solution in action on i3wm.

Vp6r052.gif

Qt Code:
  1. from PyQt5.QtCore import *
  2. from PyQt5.QtGui import *
  3. from PyQt5.QtWidgets import *
  4. import sys
  5.  
  6.  
  7. class My_Model_table(QAbstractTableModel):
  8. def __init__(self, table_data=[], parent=None):
  9. super().__init__()
  10. self.table_data = table_data
  11.  
  12. def rowCount(self, parent):
  13. return len(self.table_data)
  14.  
  15. def columnCount(self, parent):
  16. return 1
  17.  
  18. def data(self, index, role):
  19. if role == Qt.DisplayRole:
  20. value = self.table_data[index.row()]
  21. return value
  22. if role == Qt.TextAlignmentRole:
  23. return Qt.AlignCenter
  24.  
  25.  
  26. class My_table(QTableView):
  27. def __init__(self, parent=None):
  28. super().__init__()
  29. self.activated.connect(self.double_click_enter)
  30.  
  31. def double_click_enter(self, QModelIndex):
  32. row = QModelIndex.row()
  33.  
  34. self.setStyleSheet('selection-background-color:red;')
  35.  
  36. self.alarm = QTimer()
  37. self.alarm.timeout.connect(self.row_color_back)
  38. self.alarm.setSingleShot(True)
  39. self.alarm.start(200)
  40. return
  41.  
  42. def row_color_back(self):
  43. self.setStyleSheet('')
  44.  
  45.  
  46. if __name__ == '__main__':
  47. app = QApplication(sys.argv)
  48. data = ['1', '2', '3', '4', '5']
  49. main_table = My_table()
  50. main_table.setModel(My_Model_table(data))
  51.  
  52. main_table.show()
  53. sys.exit(app.exec_())
To copy to clipboard, switch view to plain text mode