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. [Solved] QComboBox change style

[Solved] QComboBox change style

Scheduled Pinned Locked Moved General and Desktop
5 Posts 2 Posters 2.8k 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.
  • S Offline
    S Offline
    Sam
    wrote on last edited by
    #1

    Hi,

    A QComboBox renders the following output when disabled/enabled

    disabled
    !http://img209.imageshack.us/img209/5448/discombo.png(disabled_combo)!

    enabled
    !http://img28.imageshack.us/img28/7385/encombo.png(enabled)!

    Is there any way that I can render the enabled style even when setEnable is false for QComboBox. My requirement is to disable item selection/showPopup for the combobox on a particular condition.

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

      Everything is possible, but why do you want to confuse your users by making it look like your combo is enabled when it is not?

      1 Reply Last reply
      0
      • S Offline
        S Offline
        Sam
        wrote on last edited by
        #3

        I have the list that contains processed and unprocessed items with different background color. The user is not allowed to change any entry if item is already processed but i want to render the enabled style for combobox as there are other components that are enabled.

        Whereas for unprocessed items the user is allowed to make changes as per requirement.

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

          It still sounds like a Bad Idea(TM) to me. However, one way is to use a proxy style on your combo box and simply manipulate the appropriate flag. Something like this should work:

          @
          class EnabledStyle: public QProxyStyle {
          public:
          virtual void drawComplexControl ( ComplexControl control, const QStyleOptionComplex * option, QPainter * painter, const QWidget * widget = 0 ) const;
          }

          void EnabledStyle::drawComplexControl ( ComplexControl control, const QStyleOptionComplex * option, QPainter * painter, const QWidget * widget ) const
          {
          if (control == CC_ComboBox && option) {
          QStyleOptionComboBox enabledOption(*option);
          enabledOption.state |= QStyle::State_Enabled;
          QProxyStyle::drawComplexControl(control, &enabledOption, painter, widget);
          } else {
          //simply pass through
          QProxyStyle::drawComplexControl(control, option, painter, widget);
          }
          }
          @

          1 Reply Last reply
          0
          • S Offline
            S Offline
            Sam
            wrote on last edited by
            #5

            @Andre

            bq. It still sounds like a Bad Idea™ to me.

            Thats's the specification I got :)

            @void EnabledStyle::drawComplexControl(QStyle::ComplexControl control, const QStyleOptionComplex *option, QPainter *painter, const QWidget *widget) const
            {
            if (control == CC_ComboBox && option)
            {
            QStyleOptionComboBox enabledOption;
            enabledOption.palette = option->palette;
            enabledOption.rect = option->rect;
            enabledOption.state |= QStyle::State_Enabled;
            painter->setPen(QColor(Qt::black));

                QProxyStyle::drawComplexControl(control, &enabledOption, painter, widget);
            
            } else {
            
                //simply pass through
                QProxyStyle::drawComplexControl(control, option, painter, widget);
            }
            

            }@

            The code works perfect , I owe you a beer :)

            Thanks.

            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