Qt Forum

    • Login
    • Search
    • Categories
    • Recent
    • Tags
    • Popular
    • Users
    • Groups
    • Search
    • Unsolved

    [Solved] QComboBox change style

    General and Desktop
    2
    5
    2368
    Loading More Posts
    • 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
      Sam last edited by

      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 Reply Quote 0
      • A
        andre last edited by

        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 Reply Quote 0
        • S
          Sam last edited by

          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 Reply Quote 0
          • A
            andre last edited by

            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 Reply Quote 0
            • S
              Sam last edited by

              @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 Reply Quote 0
              • First post
                Last post