PDA

View Full Version : Change stylesheet



leoalvesmachado
28th July 2010, 20:20
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:

<property name="styleSheet">
<string notr="true">#TopBar{
background-image: url(:/tbskin.png);
background-repeat: no-repeat;
background-color: rgba(255, 255, 255, 0);
}</string>

Full code


<?xml version="1.0" encoding="UTF-8"?>
<ui version="4.0">
<class>TopBar</class>
<widget class="QWidget" name="TopBar">
<property name="geometry">
<rect>
<x>0</x>
<y>0</y>
<width>320</width>
<height>70</height>
</rect>
</property>
<property name="minimumSize">
<size>
<width>320</width>
<height>70</height>
</size>
</property>
<property name="maximumSize">
<size>
<width>320</width>
<height>70</height>
</size>
</property>
<property name="windowTitle">
<string>Form</string>
</property>
<property name="autoFillBackground">
<bool>false</bool>
</property>
<property name="styleSheet">
<string notr="true">#TopBar{
background-image: url(:/tbskin.png);
background-repeat: no-repeat;
background-color: rgba(255, 255, 255, 0);
}</string>
</property>
<widget class="QWidget" name="verticalLayoutWidget">
<property name="geometry">
<rect>
<x>0</x>
<y>15</y>
<width>371</width>
<height>61</height>
</rect>
</property>
<layout class="QVBoxLayout" name="vertical_layout">
<property name="sizeConstraint">
<enum>QLayout::SetFixedSize</enum>
</property>
<item>
<layout class="QHBoxLayout" name="tb_layout">
<item>
<spacer name="horizontalSpacer">
<property name="orientation">
<enum>Qt::Horizontal</enum>
</property>
<property name="sizeType">
<enum>QSizePolicy::Fixed</enum>
</property>
<property name="sizeHint" stdset="0">
<size>
<width>23</width>
<height>20</height>
</size>
</property>
</spacer>
</item>
<item>
<widget class="QPushButton" name="tb_bEtc">
<property name="sizePolicy">
<sizepolicy hsizetype="Fixed" vsizetype="Fixed">
<horstretch>42</horstretch>
<verstretch>43</verstretch>
</sizepolicy>
</property>
<property name="minimumSize">
<size>
<width>42</width>
<height>43</height>
</size>
</property>
<property name="maximumSize">
<size>
<width>42</width>
<height>43</height>
</size>
</property>
<property name="styleSheet">
<string notr="true">#tb_bEtc:!pressed:!hover {
background-image: url(:/betc_normal.png);
background-repeat: no-repeat;
background-color: rgba(255, 255, 255, 0);
border:0px;
}

#tb_bEtc:pressed {
background-image: url(:/betc_press.png);
background-repeat: no-repeat;
background-color: rgba(255, 255, 255, 0);
border:0px;
}

#tb_bEtc:hover:!pressed {
background-image: url(:/betc_hover.png);
background-repeat: no-repeat;
background-color: rgba(255, 255, 255, 0);
border:0px;
}</string>
</property>
<property name="text">
<string/>
</property>
</widget>
</item>
<item>
<spacer name="hspcr_etc_pin">
<property name="orientation">
<enum>Qt::Horizontal</enum>
</property>
<property name="sizeType">
<enum>QSizePolicy::Expanding</enum>
</property>
<property name="sizeHint" stdset="0">
<size>
<width>50</width>
<height>20</height>
</size>
</property>
</spacer>
</item>
<item>
<widget class="QPushButton" name="tb_bPin">
<property name="sizePolicy">
<sizepolicy hsizetype="Fixed" vsizetype="Fixed">
<horstretch>42</horstretch>
<verstretch>43</verstretch>
</sizepolicy>
</property>
<property name="minimumSize">
<size>
<width>42</width>
<height>43</height>
</size>
</property>
<property name="maximumSize">
<size>
<width>42</width>
<height>43</height>
</size>
</property>
<property name="styleSheet">
<string notr="true">#tb_bPin:!pressed:!hover {
background-image: url(:/bpin_normal.png);
background-repeat: no-repeat;
background-color: rgba(255, 255, 255, 0);
border:0px;
}

#tb_bPin:pressed {
background-image: url(:/bpin_press.png);
background-repeat: no-repeat;
background-color: rgba(255, 255, 255, 0);
border:0px;
}

#tb_bPin:hover:!pressed {
background-image: url(:/bpin_hover.png);
background-repeat: no-repeat;
background-color: rgba(255, 255, 255, 0);
border:0px;
}</string>
</property>
<property name="text">
<string/>
</property>
</widget>
</item>
<item>
<spacer name="hspcr_pin_cls">
<property name="orientation">
<enum>Qt::Horizontal</enum>
</property>
<property name="sizeType">
<enum>QSizePolicy::Expanding</enum>
</property>
<property name="sizeHint" stdset="0">
<size>
<width>50</width>
<height>20</height>
</size>
</property>
</spacer>
</item>
<item>
<widget class="QPushButton" name="tb_bCls">
<property name="sizePolicy">
<sizepolicy hsizetype="Fixed" vsizetype="Fixed">
<horstretch>42</horstretch>
<verstretch>43</verstretch>
</sizepolicy>
</property>
<property name="minimumSize">
<size>
<width>42</width>
<height>43</height>
</size>
</property>
<property name="maximumSize">
<size>
<width>42</width>
<height>43</height>
</size>
</property>
<property name="styleSheet">
<string notr="true">#tb_bCls:!pressed:!hover {
background-image: url(:/bcls_normal.png);
background-repeat: no-repeat;
background-color: rgba(255, 255, 255, 0);
border:0px;
}

#tb_bCls:pressed {
background-image: url(:/bcls_press.png);
background-repeat: no-repeat;
background-color: rgba(255, 255, 255, 0);
border:0px;
}

#tb_bCls:hover:!pressed {
background-image: url(:/bcls_hover.png);
background-repeat: no-repeat;
background-color: rgba(255, 255, 255, 0);
border:0px;
}</string>
</property>
<property name="text">
<string/>
</property>
</widget>
</item>
<item>
<spacer name="horizontalSpacer_2">
<property name="orientation">
<enum>Qt::Horizontal</enum>
</property>
<property name="sizeType">
<enum>QSizePolicy::Fixed</enum>
</property>
<property name="sizeHint" stdset="0">
<size>
<width>20</width>
<height>20</height>
</size>
</property>
</spacer>
</item>
</layout>
</item>
</layout>
</widget>
</widget>
<resources/>
<connections/>
</ui>

Thanks in advance