Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. Specifying different iconsets for the same widget
QtWS25 Last Chance

Specifying different iconsets for the same widget

Scheduled Pinned Locked Moved General and Desktop
7 Posts 3 Posters 4.0k Views
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • R Offline
    R Offline
    rsri
    wrote on last edited by
    #1

    @ <widget class="LedButton" name="m_Standby_btn1" >

     <property name="icon" >
    
       <iconset resource="VSMgui.qrc">:/images/images/whiteCircle_nt.png</iconset>
    
     </property>
    
        <property name="text" >
    
       <string>Standby--</string>
    
     </property>
    
         <property name="visible"> <bool>false--</bool> </property>
    

    </widget>
    @
    I want to be able to display a different icon dynamically if this button is selected.
    So, I am trying to create a button with 2 png files (such that any one can be used at any point of time)>
    Is it possible to specify this in a UI file?

    Or would I have to create two buttons each with a different png file?

    Thanks

    RS

    1 Reply Last reply
    0
    • Q Offline
      Q Offline
      qxoz
      wrote on last edited by
      #2

      You can use
      @setIcon(QIcon(":/icon/SomeIcon.png"));@

      and change icon by some SIGNAL

      @setIcon(QIcon(":/icon/SomeOtherIcon.png"));@

      1 Reply Last reply
      0
      • Q Offline
        Q Offline
        qxoz
        wrote on last edited by
        #3

        Sorry i don't understood you, at first time.
        In UI file you can specify this in following way:
        @<property name="icon">
        <iconset resource="res.qrc">
        <normaloff>:/icon/Connect.png</normaloff>
        <selectedon>:/icon/Disconnect.png</selectedon>:/icon/Connect.png</iconset>
        </property>@

        or with QtCreator's interface in widgets property window(icon->Normal, Active, Selected,Disabled).

        1 Reply Last reply
        0
        • A Offline
          A Offline
          andre
          wrote on last edited by
          #4

          I'd use a style sheet for that.

          1 Reply Last reply
          0
          • R Offline
            R Offline
            rsri
            wrote on last edited by
            #5

            Thanks for the inputs.

            I had tried the setIcon() solution and it works most of the time but I keep seeing the following 2 crashes once in a while and so I have decided to implement this dynamic Icon thing in the UI file now to avoid the crash.

            This is how I had used the functions
            @
            // remove explicit reference to QPixmap to avoid the crash that happens
            // sporadically
            if (bSelected) {
            setIcon(QIcon(QString::fromUtf8(":/images/images/whiteCircle_nt.png")));
            } else {
            setIcon(QIcon(QString::fromUtf8(":/images/images/blueCircle_nt.png")));
            }
            }
            @
            Please let me know if any of you have seen such intermittent crashes wen using setIcon() function.
            @
            Crash #1 Backtrace:
            #0 0x0f89a2ac in QX11Info::visual () from /usr/lib/libQtGui.so.4
            #1 0x0f8d192c in QPixmap::toImage () from /usr/lib/libQtGui.so.4
            #2 0x0fa58918 in QCommonStyle::generatedIconPixmap () from /usr/lib/libQtGui.so.4
            #3 0x0f8a3108 in QIcon::QIcon () from /usr/lib/libQtGui.so.4
            #4 0x0f8a08d8 in QIcon::pixmap () from /usr/lib/libQtGui.so.4
            @
            OR
            @
            Crash #2 Backtrace:
            #0 0x0f2f9e00 in memcpy () from /lib/tls/libc.so.6
            #1 0x10166b90 in ?? ()
            #2 0x0f521160 in QVectorData::malloc () from /usr/lib/libQtCore.so.4
            #3 0x0f937e58 in operator<< () from /usr/lib/libQtGui.so.4
            #4 0x0f96c170 in QRegion::copy () from /usr/lib/libQtGui.so.4
            #5 0x0f96a178 in QRegion::QRegion () from /usr/lib/libQtGui.so.4
            #6 0x0f96a87c in QRegion::QRegion () from /usr/lib/libQtGui.so.4
            #7 0x0f96be30 in QRegion::unite () from /usr/lib/libQtGui.so.4
            #8 0x0f9366ec in QRegion::operator+ () from /usr/lib/libQtGui.so.4
            #9 0x0f936740 in QRegion::operator+= () from /usr/lib/libQtGui.so.4
            #10 0x0f96e7a4 in QWidgetPrivate::drawWidget () from /usr/lib/libQtGui.so.4
            #11 0x0f96f734 in QWidget::update () from /usr/lib/libQtGui.so.4
            #12 0x0f96f7b8 in QWidget::update () from /usr/lib/libQtGui.so.4
            #13 0x0f96f840 in QWidget::update () from /usr/lib/libQtGui.so.4
            #14 0x0fad686c in QAbstractButton::setIcon () from /usr/lib/libQtGui.so.4
            @

            Edit: Please use @ signs around code sections; Andre

            1 Reply Last reply
            0
            • R Offline
              R Offline
              rsri
              wrote on last edited by
              #6

              I tried qxoz's suggestion of adding the <normaloff> and <selectedon> tags but with this, no icon is generated. Here's how my UI file looks like: I even added a <normalon> tag just in case and that did not help either....

              @@
              <widget class="LedButton" name="m_Standby_btn" >
              <property name="icon">
              <iconset resource="VSMgui.qrc">
              <normalon>:/images/images/whiteCircle_nt.png</normalon>
              <normaloff>:/images/images/whiteCircle_nt.png</normaloff>
              <selectedon>:/images/images/blueCircle_nt.png</selectedon>
              </iconset>
              </property>
              <property name="text" >
              <string>Standby</string>
              </property>
              <property name="visible"> <bool>true</bool> </property>
              </widget>
              @@

              1 Reply Last reply
              0
              • R Offline
                R Offline
                rsri
                wrote on last edited by
                #7

                I tried qxoz's suggestion of adding the <normaloff> and <selectedon> tags but with this, no icon is generated. Here's how my UI file looks like: I even added a <normalon> tag just in case and that did not help either....

                @@
                <widget class="LedButton" name="m_Standby_btn" >
                <property name="icon">
                <iconset resource="VSMgui.qrc">
                <normalon>:/images/images/whiteCircle_nt.png</normalon>
                <normaloff>:/images/images/whiteCircle_nt.png</normaloff>
                <selectedon>:/images/images/blueCircle_nt.png</selectedon>
                </iconset>
                </property>
                <property name="text" >
                <string>Standby</string>
                </property>
                <property name="visible"> <bool>true</bool> </property>
                </widget>
                @@

                1 Reply Last reply
                0

                • Login

                • Login or register to search.
                • First post
                  Last post
                0
                • Categories
                • Recent
                • Tags
                • Popular
                • Users
                • Groups
                • Search
                • Get Qt Extensions
                • Unsolved