Results 1 to 7 of 7

Thread: setStyleSheet doesnt work on raspberry pi

  1. #1
    Join Date
    Jul 2019
    Posts
    6
    Thanks
    1
    Qt products
    Qt5
    Platforms
    Unix/X11 Windows

    Default setStyleSheet doesnt work on raspberry pi

    Hi to everyone,

    i developing simple screen desing but i have a problem. I write on my desktop that base linux ubuntu 16.04 and pycharm editor, when i execute code everything awesome. But i try to run on raspberry pi same code, button.setStyleSheet("background-color: red") doesnt work. Moreover i dont get any eror,it comes screen but when i clicked to button, dont change button background color.

    i want to change button background color when i clicked to button. This code running on my desktop.


    def initUI(self):
    self.btn.setToolTip('Buton1 islemleri') # Buton aciklamasini gosteriyor,uzerine gelindiginde.
    self.btn.resize(120,70) # BOYUTLANDIRMA
    self.btn.move(50, 50) # KONUMLANDIRMA
    self.btn.clicked.connect(self.buton1_event) # button1 cikis olayi

    def Ac(self,Cpin):
    GPIO.output(Cpin,GPIO.HIGH)
    def Kapat(self,Cpin):
    GPIO.output(Cpin,GPIO.LOW)


    # --------------Button1 Tiklama Olayi ------------------
    def buton1_event(self):
    if self.lcd1Bool == True:
    self.lcd1.display(1)
    self.Ac(kapaliCikis)
    self.btn.setStyleSheet("background-color: yellow") # this line doesnt work !!!
    self.lcd1Bool = False
    else:
    self.lcd1.display(0)
    self.Kapat(kapaliCikis)
    self.btn.setStyleSheet("background-color: #257c07") # this line doesnt work !!!
    self.lcd1Bool = True
    Last edited by mrtyvz41; 25th July 2019 at 13:58.

  2. #2
    Join Date
    Jan 2008
    Location
    Alameda, CA, USA
    Posts
    4,053
    Thanks
    233
    Thanked 649 Times in 639 Posts
    Qt products
    Qt5
    Platforms
    Unix/X11 Windows Android

    Default Re: setStyleSheet doesnt work on raspberry pi

    The ability to set background colors for buttons is OS dependent. If you are using Raspbian, you should do some searching to see if that OS allows such changes. I know that on Windows, it takes a lot of work to dynamically change background colors for buttons. You can find a lot of posts here concerning that.
    <=== The Great Pumpkin says ===>
    Please use CODE tags when posting source code so it is more readable. Click "Go Advanced" and then the "#" icon to insert the tags. Paste your code between them.

  3. The following user says thank you to d_stranz for this useful post:

    mrtyvz41 (26th July 2019)

  4. #3
    Join Date
    Jul 2019
    Posts
    6
    Thanks
    1
    Qt products
    Qt5
    Platforms
    Unix/X11 Windows

    Default Re: setStyleSheet doesnt work on raspberry pi

    Thank you for quickly reply, i will change rasp's operating system with ubuntu 18.04

  5. #4
    Join Date
    Jan 2006
    Location
    Graz, Austria
    Posts
    8,396
    Thanks
    37
    Thanked 1,542 Times in 1,493 Posts
    Qt products
    Qt3 Qt4 Qt5
    Platforms
    Unix/X11 Windows

    Default Re: setStyleSheet doesnt work on raspberry pi

    It is not so much operating system specific as it is style specific.

    Make sure you run the same widget style on both platforms, e.g. Qt's default style "Fusion"

    Cheers,
    _

  6. #5
    Join Date
    Jul 2019
    Posts
    6
    Thanks
    1
    Qt products
    Qt5
    Platforms
    Unix/X11 Windows

    Default Re: setStyleSheet doesnt work on raspberry pi

    Hello again,

    i install ubuntu-mate-18.04.2 on my raspberry but not change.

    This is all of my code:
    Qt Code:
    1. import sys
    2. import RPi.GPIO as GPIO
    3. import time
    4. import subprocess
    5. from PyQt5.QtWidgets import (QWidget, QToolTip,
    6. from PyQt5.QtCore import *
    7. from PyQt5.QtGui import *
    8.  
    9. GPIO.setmode(GPIO.BOARD)
    10. #--------------Degiskenler---------------
    11. #Girisler
    12.  
    13. #Cikislar
    14. kapaliCikis= 16
    15. yolcuCikis = 22
    16. soforCikis = 24
    17. geceLambaCikis = 26
    18. aydinlatmaCikis = 32
    19. hostesIkazCikis = 36
    20.  
    21.  
    22. #-----------Tanimlamalar-----------------
    23. #Giris
    24. #GPIO.setup(fanButton,GPIO.IN)
    25. #GPIO.setup(durdurButton,GPIO.IN)
    26.  
    27.  
    28. #--------------Cikislar---------------------
    29. GPIO.setup(kapaliCikis,GPIO.OUT)
    30. GPIO.setup(yolcuCikis,GPIO.OUT)
    31. GPIO.setup(soforCikis,GPIO.OUT)
    32. GPIO.setup(geceLambaCikis,GPIO.OUT)
    33. GPIO.setup(aydinlatmaCikis,GPIO.OUT)
    34. GPIO.setup(hostesIkazCikis,GPIO.OUT)
    35.  
    36.  
    37. class Example():
    38.  
    39.  
    40.  
    41. def __init__(self):
    42. self.fanhiz = 10
    43.  
    44. self.dnm = QWidget()
    45.  
    46.  
    47. #------------------BUTTONLAR--------------------------
    48. self.btn = QPushButton('Kapali',self.dnm)
    49. self.btn2 = QPushButton('Yolcu Alma',self.dnm)
    50. self.btn3 = QPushButton('Sofor Kontrol',self.dnm)
    51. self.btn4 = QPushButton('Gece Lamblari',self.dnm)
    52. self.btn5 = QPushButton('Aydinlatma',self.dnm)
    53. self.btn6 = QPushButton('Hostes ikaz',self.dnm)
    54.  
    55.  
    56. #-------------- BUTTON 1 LCD GOSTERICISI---------------
    57. self.lcd1 = QLCDNumber(self.dnm)
    58. self.lcd1.resize(200,70)
    59. self.lcd1.move(175,50)
    60.  
    61.  
    62. #-------------BUTTON 2 LCD GOSTERICISI-----------------
    63. self.lcd2 = QLCDNumber(self.dnm)
    64. self.lcd2.resize(200,70)
    65. self.lcd2.move(525,50)
    66.  
    67. #-------------BUTTON 3 LCD GOSTERICISI-----------------
    68. self.lcd3 = QLCDNumber(self.dnm)
    69. self.lcd3.resize(200,70)
    70. self.lcd3.move(175,150)
    71.  
    72. #-------------BUTTON 4 LCD GOSTERICISI-----------------
    73. self.lcd4 = QLCDNumber(self.dnm)
    74. self.lcd4.resize(200,70)
    75. self.lcd4.move(525,150)
    76.  
    77. #-------------BUTTON 5 LCD GOSTERICISI-----------------
    78. self.lcd5 = QLCDNumber(self.dnm)
    79. self.lcd5.resize(200,70)
    80. self.lcd5.move(175,250)
    81.  
    82. #-------------BUTTON 6 LCD GOSTERICISI-----------------
    83. self.lcd6 = QLCDNumber(self.dnm)
    84. self.lcd6.resize(200,70)
    85. self.lcd6.move(525,250)
    86.  
    87.  
    88. #-------------LCD Dokunma islemi islemleri icin bool degiskenleri-----------------
    89. self.lcd6Bool = True
    90. self.lcd5Bool = True
    91. self.lcd4Bool = True
    92. self.lcd3Bool = True
    93. self.lcd2Bool = True
    94. self.lcd1Bool = True
    95. self.btnState = False
    96. self.initUI()
    97.  
    98.  
    99.  
    100.  
    101. def initUI(self):
    102.  
    103. QToolTip.setFont(QFont('SansSerif', 10))
    104. #--------------- Kapali -----------------------
    105. self.btn.setToolTip('Buton1 islemleri') # Buton aciklamasini gosteriyor,uzerine gelindiginde.
    106. self.btn.resize(120,70) # BOYUTLANDIRMA
    107. self.btn.move(50, 50) # KONUMLANDIRMA
    108. self.btn.clicked.connect(self.buton1_event) # button1 cikis olayi
    109. self.btn.setAutoFillBackground(True)
    110.  
    111. #--------------- Yolcu Alma -----------------------
    112. self.btn2.setToolTip('Buton2 islemleri')
    113. self.btn2.setFont(QFont('Times',10))
    114. self.btn2.resize(120,70)
    115. self.btn2.move(400, 50)
    116. self.btn2.clicked.connect(self.buton2_event) # button2 cikis olayi
    117.  
    118.  
    119. #--------------- Sofor Kontrol -----------------------
    120. self.btn3.setFont(QFont('Times',10))
    121. self.btn3.resize(120,70)
    122. self.btn3.move(50,150)
    123. self.btn3.clicked.connect(self.buton3_event)
    124.  
    125.  
    126. #--------------- Gece Lambalari -----------------------
    127. self.btn4.setFont(QFont('Times',10))
    128. self.btn4.resize(120,70)
    129. self.btn4.move(400,150)
    130. self.btn4.clicked.connect(self.buton4_event)
    131.  
    132.  
    133. #--------------- Aydinlatma ---------------------------
    134. self.btn5.setFont(QFont('Times',10))
    135. self.btn5.resize(120,70)
    136. self.btn5.move(50,250)
    137. self.btn5.clicked.connect(self.buton5_event)
    138.  
    139. #--------------- Hostes Ikaz(imput) -----------------------
    140. self.btn6.setFont(QFont('Times',10))
    141. self.btn6.resize(120,70)
    142. self.btn6.move(400,250)
    143. self.btn6.clicked.connect(self.buton6_event)
    144.  
    145. #--------------- Cikis -----------------------
    146. cikis = QPushButton('Cikis',self.dnm)
    147. cikis.setToolTip('Uygulama Kapanir')
    148. cikis.resize(120,70)
    149. cikis.move(340,350)
    150. cikis.clicked.connect(QApplication.instance().quit) # cikis buttonu
    151.  
    152. self.dnm.setGeometry(300, 300, 800, 480)
    153. #self.dnm.showFullScreen()
    154. self.dnm.setWindowTitle('pi ekran')
    155. #self.dnm.setWindowIcon(QIcon('/img/inovar.png')) # icon gostermiyor.!!
    156. self.dnm.show()
    157.  
    158. def Ac(self,Cpin):
    159. GPIO.output(Cpin,GPIO.HIGH)
    160. def Kapat(self,Cpin):
    161. GPIO.output(Cpin,GPIO.LOW)
    162.  
    163.  
    164. # --------------Button1 Tiklama Olayi ------------------
    165. def buton1_event(self):
    166. if self.lcd1Bool == True:
    167. self.lcd1.display(1)
    168. self.Ac(kapaliCikis)
    169. self.btn.setStyleSheet("background-color: yellow")
    170. self.lcd1Bool = False
    171. else:
    172. self.lcd1.display(0)
    173. self.Kapat(kapaliCikis)
    174. self.btn.setStyleSheet("background-color: #257c07")
    175. self.lcd1Bool = True
    176.  
    177. # --------------Button2 Tiklama Olayi ------------------
    178. def buton2_event(self):
    179. if self.lcd2Bool == True:
    180. self.lcd2.display(1)
    181. self.Ac(yolcuCikis)
    182. self.lcd2Bool = False
    183. else:
    184. self.lcd2.display(0)
    185. self.Kapat(yolcuCikis)
    186. self.lcd2Bool = True
    187.  
    188.  
    189. # --------------Button3 Tiklama Olayi ------------------
    190. def buton3_event(self):
    191. if self.lcd3Bool == True:
    192. self.lcd3.display(1)
    193. self.Ac(soforCikis)
    194. self.lcd3Bool = False
    195. else:
    196. self.lcd3.display(0)
    197. self.Kapat(soforCikis)
    198. self.lcd3Bool = True
    199.  
    200.  
    201. #--------------Button4 Tiklama Olayi ------------------
    202. def buton4_event(self):
    203. if self.lcd4Bool == True:
    204. self.lcd4.display(1)
    205. self.Ac(geceLambaCikis)
    206. self.lcd4Bool = False
    207. else:
    208. self.lcd4.display(0)
    209. self.Kapat(geceLambaCikis)
    210. self.lcd4Bool = True
    211.  
    212.  
    213. #--------------Button5 Tiklama Olayi ------------------
    214. def buton5_event(self):
    215. if self.lcd5Bool == True:
    216. self.lcd5.display(1)
    217. self.Ac(aydinlatmaCikis)
    218. self.lcd5Bool = False
    219. else:
    220. self.lcd5.display(0)
    221. self.Kapat(aydinlatmaCikis)
    222. self.lcd5Bool = True
    223.  
    224. #--------------Button6 Tiklama Olayi ------------------
    225. def buton6_event(self):
    226. if self.lcd6Bool == True:
    227. self.lcd6.display(1)
    228. self.Ac(hostesIkazCikis)
    229. self.lcd6Bool = False
    230. else:
    231. self.lcd6.display(0)
    232. self.Kapat(hostesIkazCikis)
    233. self.lcd6Bool = True
    234.  
    235.  
    236.  
    237.  
    238.  
    239.  
    240.  
    241.  
    242.  
    243.  
    244.  
    245.  
    246.  
    247.  
    248.  
    249.  
    250.  
    251. if __name__ == '__main__':
    252.  
    253. app = QApplication(sys.argv)
    254. ex = Example()
    255. """
    256.  
    257. dnm = QWidget()
    258. QToolTip.setFont(QFont('SansSerif', 10))
    259. dnm.setGeometry(300, 300, 800, 480)
    260. dnm.setWindowTitle('pi ekran2')
    261. dnm.show()
    262. """
    263. sys.exit(app.exec_())
    To copy to clipboard, switch view to plain text mode 

    Video link:
    https://www.youtube.com/watch?v=NncZ...ature=youtu.be

  7. #6
    Join Date
    Jan 2008
    Location
    Alameda, CA, USA
    Posts
    4,053
    Thanks
    233
    Thanked 649 Times in 639 Posts
    Qt products
    Qt5
    Platforms
    Unix/X11 Windows Android

    Default Re: setStyleSheet doesnt work on raspberry pi

    Instead of using a style sheet, can you try changing the color using the QPalette? In C++, this would be:

    Qt Code:
    1. QPalette pal = button.palette();
    2. pal.setColor( QPalette::Window, QColor( "yellow" ) );
    3. button.setPalette( pal );
    To copy to clipboard, switch view to plain text mode 

    If this works, it might indicate that style sheets are not fully implemented on your RasPi's version of Qt. If it doesn't work, then it could be something to do with the default style as anda_skoa suggests.
    <=== The Great Pumpkin says ===>
    Please use CODE tags when posting source code so it is more readable. Click "Go Advanced" and then the "#" icon to insert the tags. Paste your code between them.

  8. #7
    Join Date
    Jul 2019
    Posts
    6
    Thanks
    1
    Qt products
    Qt5
    Platforms
    Unix/X11 Windows

    Default Re: setStyleSheet doesnt work on raspberry pi

    Thank you for your reply

    I dont solve this problem, i used text label instead of button. Thats enough for me..

Similar Threads

  1. phonon not work on raspberry
    By iskenderoguz in forum Qt for Embedded and Mobile
    Replies: 0
    Last Post: 1st March 2015, 16:00
  2. Shortcut doesnt work
    By tuli in forum Qt Programming
    Replies: 0
    Last Post: 18th September 2012, 15:01
  3. Qwt Tex Text Doesnt work for me
    By gbmtoday in forum Qwt
    Replies: 1
    Last Post: 21st November 2010, 19:48
  4. connect doesnt work
    By john_god in forum Newbie
    Replies: 4
    Last Post: 23rd November 2008, 09:36
  5. How come this doesnt work?
    By ShaChris23 in forum Newbie
    Replies: 8
    Last Post: 16th June 2007, 04:43

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Digia, Qt and their respective logos are trademarks of Digia Plc in Finland and/or other countries worldwide.