Results 1 to 1 of 1

Thread: Change stylesheet

  1. #1
    Join Date
    Apr 2010
    Location
    Porto Alegre, RS, Brazil
    Posts
    37
    Thanks
    9
    Thanked 1 Time in 1 Post
    Qt products
    Qt4
    Platforms
    Windows

    Question Change stylesheet

    Hi everyone.
    I've created a chrome menu for widgets that I use in my application. The code (XML) is the one in the end of this post.
    I've created it using QT Creator Design tool. It works fine. However, as you can see, it has a property named styleSheet, that refers to an image, and I want this image to change in runtime. In my application, the image should be one for the "active widget" and other for "not active widgets", that's why I want to change it.
    If I make a reference for the property styleSheet, I get a compiler error "has no member named styleSheet".

    Can anyone help me?
    If doing what is needed requires throw away this xml and use only C++, I'm ok with that, but just tell me how

    The style I want to change:
    Qt Code:
    1. <property name="styleSheet">
    2. <string notr="true">#TopBar{
    3. background-image: url(:/tbskin.png);
    4. background-repeat: no-repeat;
    5. background-color: rgba(255, 255, 255, 0);
    6. }</string>
    To copy to clipboard, switch view to plain text mode 

    Full code

    Qt Code:
    1. <?xml version="1.0" encoding="UTF-8"?>
    2. <ui version="4.0">
    3. <class>TopBar</class>
    4. <widget class="QWidget" name="TopBar">
    5. <property name="geometry">
    6. <rect>
    7. <x>0</x>
    8. <y>0</y>
    9. <width>320</width>
    10. <height>70</height>
    11. </rect>
    12. </property>
    13. <property name="minimumSize">
    14. <size>
    15. <width>320</width>
    16. <height>70</height>
    17. </size>
    18. </property>
    19. <property name="maximumSize">
    20. <size>
    21. <width>320</width>
    22. <height>70</height>
    23. </size>
    24. </property>
    25. <property name="windowTitle">
    26. <string>Form</string>
    27. </property>
    28. <property name="autoFillBackground">
    29. <bool>false</bool>
    30. </property>
    31. <property name="styleSheet">
    32. <string notr="true">#TopBar{
    33. background-image: url(:/tbskin.png);
    34. background-repeat: no-repeat;
    35. background-color: rgba(255, 255, 255, 0);
    36. }</string>
    37. </property>
    38. <widget class="QWidget" name="verticalLayoutWidget">
    39. <property name="geometry">
    40. <rect>
    41. <x>0</x>
    42. <y>15</y>
    43. <width>371</width>
    44. <height>61</height>
    45. </rect>
    46. </property>
    47. <layout class="QVBoxLayout" name="vertical_layout">
    48. <property name="sizeConstraint">
    49. <enum>QLayout::SetFixedSize</enum>
    50. </property>
    51. <item>
    52. <layout class="QHBoxLayout" name="tb_layout">
    53. <item>
    54. <spacer name="horizontalSpacer">
    55. <property name="orientation">
    56. <enum>Qt::Horizontal</enum>
    57. </property>
    58. <property name="sizeType">
    59. <enum>QSizePolicy::Fixed</enum>
    60. </property>
    61. <property name="sizeHint" stdset="0">
    62. <size>
    63. <width>23</width>
    64. <height>20</height>
    65. </size>
    66. </property>
    67. </spacer>
    68. </item>
    69. <item>
    70. <widget class="QPushButton" name="tb_bEtc">
    71. <property name="sizePolicy">
    72. <sizepolicy hsizetype="Fixed" vsizetype="Fixed">
    73. <horstretch>42</horstretch>
    74. <verstretch>43</verstretch>
    75. </sizepolicy>
    76. </property>
    77. <property name="minimumSize">
    78. <size>
    79. <width>42</width>
    80. <height>43</height>
    81. </size>
    82. </property>
    83. <property name="maximumSize">
    84. <size>
    85. <width>42</width>
    86. <height>43</height>
    87. </size>
    88. </property>
    89. <property name="styleSheet">
    90. <string notr="true">#tb_bEtc:!pressed:!hover {
    91. background-image: url(:/betc_normal.png);
    92. background-repeat: no-repeat;
    93. background-color: rgba(255, 255, 255, 0);
    94. border:0px;
    95. }
    96.  
    97. #tb_bEtc:pressed {
    98. background-image: url(:/betc_press.png);
    99. background-repeat: no-repeat;
    100. background-color: rgba(255, 255, 255, 0);
    101. border:0px;
    102. }
    103.  
    104. #tb_bEtc:hover:!pressed {
    105. background-image: url(:/betc_hover.png);
    106. background-repeat: no-repeat;
    107. background-color: rgba(255, 255, 255, 0);
    108. border:0px;
    109. }</string>
    110. </property>
    111. <property name="text">
    112. <string/>
    113. </property>
    114. </widget>
    115. </item>
    116. <item>
    117. <spacer name="hspcr_etc_pin">
    118. <property name="orientation">
    119. <enum>Qt::Horizontal</enum>
    120. </property>
    121. <property name="sizeType">
    122. <enum>QSizePolicy::Expanding</enum>
    123. </property>
    124. <property name="sizeHint" stdset="0">
    125. <size>
    126. <width>50</width>
    127. <height>20</height>
    128. </size>
    129. </property>
    130. </spacer>
    131. </item>
    132. <item>
    133. <widget class="QPushButton" name="tb_bPin">
    134. <property name="sizePolicy">
    135. <sizepolicy hsizetype="Fixed" vsizetype="Fixed">
    136. <horstretch>42</horstretch>
    137. <verstretch>43</verstretch>
    138. </sizepolicy>
    139. </property>
    140. <property name="minimumSize">
    141. <size>
    142. <width>42</width>
    143. <height>43</height>
    144. </size>
    145. </property>
    146. <property name="maximumSize">
    147. <size>
    148. <width>42</width>
    149. <height>43</height>
    150. </size>
    151. </property>
    152. <property name="styleSheet">
    153. <string notr="true">#tb_bPin:!pressed:!hover {
    154. background-image: url(:/bpin_normal.png);
    155. background-repeat: no-repeat;
    156. background-color: rgba(255, 255, 255, 0);
    157. border:0px;
    158. }
    159.  
    160. #tb_bPin:pressed {
    161. background-image: url(:/bpin_press.png);
    162. background-repeat: no-repeat;
    163. background-color: rgba(255, 255, 255, 0);
    164. border:0px;
    165. }
    166.  
    167. #tb_bPin:hover:!pressed {
    168. background-image: url(:/bpin_hover.png);
    169. background-repeat: no-repeat;
    170. background-color: rgba(255, 255, 255, 0);
    171. border:0px;
    172. }</string>
    173. </property>
    174. <property name="text">
    175. <string/>
    176. </property>
    177. </widget>
    178. </item>
    179. <item>
    180. <spacer name="hspcr_pin_cls">
    181. <property name="orientation">
    182. <enum>Qt::Horizontal</enum>
    183. </property>
    184. <property name="sizeType">
    185. <enum>QSizePolicy::Expanding</enum>
    186. </property>
    187. <property name="sizeHint" stdset="0">
    188. <size>
    189. <width>50</width>
    190. <height>20</height>
    191. </size>
    192. </property>
    193. </spacer>
    194. </item>
    195. <item>
    196. <widget class="QPushButton" name="tb_bCls">
    197. <property name="sizePolicy">
    198. <sizepolicy hsizetype="Fixed" vsizetype="Fixed">
    199. <horstretch>42</horstretch>
    200. <verstretch>43</verstretch>
    201. </sizepolicy>
    202. </property>
    203. <property name="minimumSize">
    204. <size>
    205. <width>42</width>
    206. <height>43</height>
    207. </size>
    208. </property>
    209. <property name="maximumSize">
    210. <size>
    211. <width>42</width>
    212. <height>43</height>
    213. </size>
    214. </property>
    215. <property name="styleSheet">
    216. <string notr="true">#tb_bCls:!pressed:!hover {
    217. background-image: url(:/bcls_normal.png);
    218. background-repeat: no-repeat;
    219. background-color: rgba(255, 255, 255, 0);
    220. border:0px;
    221. }
    222.  
    223. #tb_bCls:pressed {
    224. background-image: url(:/bcls_press.png);
    225. background-repeat: no-repeat;
    226. background-color: rgba(255, 255, 255, 0);
    227. border:0px;
    228. }
    229.  
    230. #tb_bCls:hover:!pressed {
    231. background-image: url(:/bcls_hover.png);
    232. background-repeat: no-repeat;
    233. background-color: rgba(255, 255, 255, 0);
    234. border:0px;
    235. }</string>
    236. </property>
    237. <property name="text">
    238. <string/>
    239. </property>
    240. </widget>
    241. </item>
    242. <item>
    243. <spacer name="horizontalSpacer_2">
    244. <property name="orientation">
    245. <enum>Qt::Horizontal</enum>
    246. </property>
    247. <property name="sizeType">
    248. <enum>QSizePolicy::Fixed</enum>
    249. </property>
    250. <property name="sizeHint" stdset="0">
    251. <size>
    252. <width>20</width>
    253. <height>20</height>
    254. </size>
    255. </property>
    256. </spacer>
    257. </item>
    258. </layout>
    259. </item>
    260. </layout>
    261. </widget>
    262. </widget>
    263. <resources/>
    264. <connections/>
    265. </ui>
    To copy to clipboard, switch view to plain text mode 

    Thanks in advance
    Last edited by leoalvesmachado; 28th July 2010 at 21:25.

Similar Threads

  1. DockWidgetArea change and layout direction change
    By mstegehu in forum Qt Programming
    Replies: 1
    Last Post: 21st February 2012, 22:24
  2. Change Stylesheet Using Dynamic Property
    By stefanadelbert in forum Qt Programming
    Replies: 4
    Last Post: 26th August 2010, 08:48
  3. Replies: 2
    Last Post: 21st March 2010, 09:20
  4. stylesheet
    By BalaQT in forum Qt Programming
    Replies: 2
    Last Post: 19th March 2010, 08:45
  5. Replies: 8
    Last Post: 15th May 2007, 10:21

Tags for this Thread

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.