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. drawing complex controls

drawing complex controls

Scheduled Pinned Locked Moved Unsolved General and Desktop
7 Posts 3 Posters 740 Views 1 Watching
  • 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.
  • H Offline
    H Offline
    happ
    wrote on last edited by
    #1

    How do I draw complex controls using qstyle?
    I reimplement drawComplex like other types but nothing happens.

    Pl45m4P 1 Reply Last reply
    0
    • H happ

      How do I draw complex controls using qstyle?
      I reimplement drawComplex like other types but nothing happens.

      Pl45m4P Offline
      Pl45m4P Offline
      Pl45m4
      wrote on last edited by
      #2

      @happ said in drawing complex controls:

      How do I draw complex controls using qstyle?
      I reimplement drawComplex like other types but nothing happens.

      That's not much information.

      Show what you did exactly.


      If debugging is the process of removing software bugs, then programming must be the process of putting them in.

      ~E. W. Dijkstra

      H 1 Reply Last reply
      0
      • Pl45m4P Pl45m4

        @happ said in drawing complex controls:

        How do I draw complex controls using qstyle?
        I reimplement drawComplex like other types but nothing happens.

        That's not much information.

        Show what you did exactly.

        H Offline
        H Offline
        happ
        wrote on last edited by
        #3

        @Pl45m4 whenever i set my custom style to my app (QApplication) all the complex controls disappear).
        this is the drawComplex code that i've written:

        void ChangeSlider(const QStyleOptionComplex *opt, QPainter* painter, const QWidget* w)
        {
            if(opt->state == QStyle::State_Active)
            {
                if(opt->activeSubControls == QStyle::SC_SliderHandle)
                {
                    painter->setBrush(QColor(0xe6, 0x00, 0x00));
                    painter->setPen(QColor(0xe6, 0x00, 0x00));
                }
                else if(opt->activeSubControls == QStyle::SC_SliderHandle)
                {
                    painter->setBrush(QColor(0x4D, 0xA6, 0xFF));
                    painter->setPen(QColor(0x4D, 0xA6, 0xFF));
                }
            }
            painter->drawRect(opt->rect);
        }
        
        void GlobalStyles::drawComplexControl(ComplexControl cc, const QStyleOptionComplex *opt, QPainter *p,
                                  const QWidget *w) const
        {
              switch(cc)
              {
              case QStyle::CC_Slider:
                  ChangeSlider(opt, p, w);
                  return;
              default:
                  QCommonStyle::drawComplexControl(cc,opt,p,w);
              }
        
         }
        

        what am i doing wrong here?

        Pl45m4P M 2 Replies Last reply
        0
        • H happ

          @Pl45m4 whenever i set my custom style to my app (QApplication) all the complex controls disappear).
          this is the drawComplex code that i've written:

          void ChangeSlider(const QStyleOptionComplex *opt, QPainter* painter, const QWidget* w)
          {
              if(opt->state == QStyle::State_Active)
              {
                  if(opt->activeSubControls == QStyle::SC_SliderHandle)
                  {
                      painter->setBrush(QColor(0xe6, 0x00, 0x00));
                      painter->setPen(QColor(0xe6, 0x00, 0x00));
                  }
                  else if(opt->activeSubControls == QStyle::SC_SliderHandle)
                  {
                      painter->setBrush(QColor(0x4D, 0xA6, 0xFF));
                      painter->setPen(QColor(0x4D, 0xA6, 0xFF));
                  }
              }
              painter->drawRect(opt->rect);
          }
          
          void GlobalStyles::drawComplexControl(ComplexControl cc, const QStyleOptionComplex *opt, QPainter *p,
                                    const QWidget *w) const
          {
                switch(cc)
                {
                case QStyle::CC_Slider:
                    ChangeSlider(opt, p, w);
                    return;
                default:
                    QCommonStyle::drawComplexControl(cc,opt,p,w);
                }
          
           }
          

          what am i doing wrong here?

          Pl45m4P Offline
          Pl45m4P Offline
          Pl45m4
          wrote on last edited by Pl45m4
          #4

          @happ

          So you custom slider subclass has GlobalStyles style set?!
          Do you only call style()->drawComplexControl(........) within the sliders paintEvent?
          Otherwise it would get overridden.

          If you look at QSliders default implementation:
          Qt6

          void QSlider::paintEvent(QPaintEvent *)
          {
              Q_D(QSlider);
              QStylePainter p(this);
              QStyleOptionSlider opt;
              initStyleOption(&opt);
              opt.subControls = QStyle::SC_SliderGroove | QStyle::SC_SliderHandle;
              if (d->tickPosition != NoTicks)
                  opt.subControls |= QStyle::SC_SliderTickmarks;
              p.drawComplexControl(QStyle::CC_Slider, opt);
          }
          

          Qt5 (slightly different)

          void QSlider::paintEvent(QPaintEvent *)
          {
              Q_D(QSlider);
              QPainter p(this);
              QStyleOptionSlider opt;
              initStyleOption(&opt);
              opt.subControls = QStyle::SC_SliderGroove | QStyle::SC_SliderHandle;
              if (d->tickPosition != NoTicks)
                  opt.subControls |= QStyle::SC_SliderTickmarks;
              if (d->pressedControl) {
                  opt.activeSubControls = d->pressedControl;
                  opt.state |= QStyle::State_Sunken;
              } else {
                  opt.activeSubControls = d->hoverControl;
              }
              style()->drawComplexControl(QStyle::CC_Slider, &opt, &p, this);
          }
          

          @happ said in drawing complex controls:

          whenever i set my custom style to my app (QApplication) all the complex controls disappear).

          Edit:

          Haven't seen that... ;-)
          I assume because your style only contains information on how to draw a QSlider.
          You might have lost everything else.

          (not sure about that, maybe somebody else can verify that)


          If debugging is the process of removing software bugs, then programming must be the process of putting them in.

          ~E. W. Dijkstra

          1 Reply Last reply
          0
          • H happ

            @Pl45m4 whenever i set my custom style to my app (QApplication) all the complex controls disappear).
            this is the drawComplex code that i've written:

            void ChangeSlider(const QStyleOptionComplex *opt, QPainter* painter, const QWidget* w)
            {
                if(opt->state == QStyle::State_Active)
                {
                    if(opt->activeSubControls == QStyle::SC_SliderHandle)
                    {
                        painter->setBrush(QColor(0xe6, 0x00, 0x00));
                        painter->setPen(QColor(0xe6, 0x00, 0x00));
                    }
                    else if(opt->activeSubControls == QStyle::SC_SliderHandle)
                    {
                        painter->setBrush(QColor(0x4D, 0xA6, 0xFF));
                        painter->setPen(QColor(0x4D, 0xA6, 0xFF));
                    }
                }
                painter->drawRect(opt->rect);
            }
            
            void GlobalStyles::drawComplexControl(ComplexControl cc, const QStyleOptionComplex *opt, QPainter *p,
                                      const QWidget *w) const
            {
                  switch(cc)
                  {
                  case QStyle::CC_Slider:
                      ChangeSlider(opt, p, w);
                      return;
                  default:
                      QCommonStyle::drawComplexControl(cc,opt,p,w);
                  }
            
             }
            

            what am i doing wrong here?

            M Offline
            M Offline
            medyakovvit
            wrote on last edited by
            #5

            @happ Does your style inherit QCommonStyle? If you want other widgets to look like there is no custom style then you can use proxy style.
            And here is how you create your style:

            auto proxy = new MyProxyStyle(QApplication::style()->name());
            proxy->setParent(widget);   // take ownership to avoid memleak
            widget->setStyle(proxy);
            

            Notice that the name of the default application style is used to create a proxy style.

            There are a layer of OS-dependent styles where an OS-specific drawing happens but they are private. The QCommonStyle probably contains some general drawing only.

            H 1 Reply Last reply
            0
            • M medyakovvit

              @happ Does your style inherit QCommonStyle? If you want other widgets to look like there is no custom style then you can use proxy style.
              And here is how you create your style:

              auto proxy = new MyProxyStyle(QApplication::style()->name());
              proxy->setParent(widget);   // take ownership to avoid memleak
              widget->setStyle(proxy);
              

              Notice that the name of the default application style is used to create a proxy style.

              There are a layer of OS-dependent styles where an OS-specific drawing happens but they are private. The QCommonStyle probably contains some general drawing only.

              H Offline
              H Offline
              happ
              wrote on last edited by
              #6

              @medyakovvit

              I was inheriting QCommonStyle when i used QProxyStyle they started showing up but my changes aren't still being implemented.

              M 1 Reply Last reply
              0
              • H happ

                @medyakovvit

                I was inheriting QCommonStyle when i used QProxyStyle they started showing up but my changes aren't still being implemented.

                M Offline
                M Offline
                medyakovvit
                wrote on last edited by
                #7

                @happ I mean that you can inherit your style from QProxyStyle instead of QCommonStyle

                class CustomStyle : public QProxyStyle
                {
                public:
                    CustomStyle(cosnt QString styleName): QProxyStyle(styleName) {...}
                
                    virtual void drawComplexControl(ComplexControl cc, const QStyleOptionComplex *opt, QPainter *p, const QWidget *w) const override
                    {
                        switch(cc)
                        {
                            case QStyle::CC_Slider:
                              // draw your slider
                            return;
                    
                          default: QProxyStyle::drawComplexControl(cc,opt,p,w);
                    }
                }
                
                // In the code where you create the slider
                auto slider = new QSlider();
                auto proxy = new CustomStyle(QApplication::style()->name());
                proxy->setParent(slider);   // take ownership to avoid memleak
                slider->setStyle(proxy);
                1 Reply Last reply
                1

                • Login

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