Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8105343
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 6, 20262026-06-06T00:08:06+00:00 2026-06-06T00:08:06+00:00

I have a class in Qt that inherits QDockWidget. And that class contains another

  • 0

I have a class in Qt that inherits QDockWidget. And that class contains another widget.
Is there any possibility to define a function in my QDockWidget inherited class that draws stuff on top of the contained widget? Like the painting to be independent of the contained widget but to be linked to the inherited class.

Thank you

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-06T00:08:09+00:00Added an answer on June 6, 2026 at 12:08 am

    Sure it’s possible. It is fairly simple to do, in fact. You need to place a child widget that sits on top of everything else in your QDockWidget. To do it so, it must be the last child widget you add to your dockwidget. That widget must not to draw its background, and it can then draw over any children of the dockwidget. The widget’s size must track the size of the parent widget.

    Below is a self-contained example.

    Screenshot of the example

    // https://github.com/KubaO/stackoverflown/tree/master/questions/overlay-line-11034838
    #include <QtGui>
    #if QT_VERSION > QT_VERSION_CHECK(5,0,0)
    #include <QtWidgets>
    #endif
    
    class Line : public QWidget {
    protected:
       void paintEvent(QPaintEvent *) override {
            QPainter p(this);
            p.setRenderHint(QPainter::Antialiasing);
            p.drawLine(rect().topLeft(), rect().bottomRight());
        }
    public:
        explicit Line(QWidget *parent = nullptr) : QWidget(parent) {
           setAttribute(Qt::WA_TransparentForMouseEvents);
        }
    };
    
    class Window : public QWidget {
        QHBoxLayout layout{this};
        QPushButton left{"Left"};
        QLabel right{"Right"};
        Line line{this};
    protected:
        void resizeEvent(QResizeEvent *) override {
            line.resize(size());
        }
    public:
        explicit Window(QWidget *parent = nullptr) : QWidget(parent) {
            layout.addWidget(&left);
            right.setFrameStyle(QFrame::Box | QFrame::Raised);
            layout.addWidget(&right);
            line.raise();
        }
    };
    
    int main(int argc, char *argv[]) {
        QApplication app(argc, argv);
        Window w;
        w.show();
        return app.exec();
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a class that inherits from a base class (this contains a lot
I have one class that inherits another. I want to use reflection to cycle
I have a class that inherits a base class to which another class has
I have a class A and another class that inherits from it, B. I
I have a class that inherits from a another class. I am overloading one
I have a class that inherits ActiveRecordValidationBase that contains the following property: [Property] [ValidateDecimal]
I have a class ShipmentsCollection that inherits ObservableCollection which contains shipment objects (entities). This
I have a class that inherits from a generic dictionary as follows: Class myClass
I have a class that inherits QMainWindow and I just want it to have
I have a class that inherits from Page, called APage. public abstract class APage:

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.