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. Overriding a classes paintevent function when its called from within a class.

Overriding a classes paintevent function when its called from within a class.

Scheduled Pinned Locked Moved General and Desktop
3 Posts 3 Posters 2.0k 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.
  • C Offline
    C Offline
    Chrisw01
    wrote on last edited by
    #1

    Hi, How would you go about overriding the paintevent of a class when its called within another class.
    e.g.
    @
    myClass::myClass(QWidget *parent) : QWidget(parent)
    {
    this->progressBar = new QProgressBar(this);
    }
    @

    I wish to override the progressBar paintevent from within the myClass class.

    Thanks.

    1 Reply Last reply
    0
    • S Offline
      S Offline
      Soraltan
      wrote on last edited by
      #2

      Hi,

      I'm not sure what you want to do. If you want to override the panitEvent of the QProgressBar you will have to derive a subclass from it and use that.

      bq. I wish to override the progressBar paintevent from within the myClass class.

      So you want to provide an implementation to overrider method x which is a member of class A from method y which is a member of class B. C++ is renown to allow all sort of fuzzy stuff, but I still doubt that is possible.

      Or didn't I get you point?!?

      Best

      Soraltan

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

        It is possible in Qt, because it is an event. Events can be intercepted by using an eventFilter. To do that, you do something like this:

        @
        myClass::myClass(QWidget *parent) : QWidget(parent)
        {
        this->progressBar = new QProgressBar(this);
        progressBar->installEventFilter(this);
        }

        bool myClass::eventFilter(QObject* o, QEvent* e)
        {
        if (o==progressBar && e && e->type() == QEvent::PaintEvent) {
        //handle the paint event for the widget
        return true; // if you want to stop the original paint event from arriving
        }

        // call base class implementation
        return QWidget::eventFilter(o, e);
        

        }
        @

        However, I think that it is probably the wrong way to do whatever you want to achieve. I think you should probably subclass QProgressBar, use a custom style on the progress bar, or use a style sheet on it. It depends on what you want to achieve, and there may be more than one way to do it.

        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