Search code examples
c++qtqt5qpainterpaintevent

How to draw a line over widget in Qt5


I have a mainwindow and more than two widget on mainwindow. I wanna draw lines on the whole mainwindow and when the line should be over the widgets not behind these widgets. I've tried overwrite paintevent function of mainwindow and draw a line directly but the line is behind widgets. What should I do?


Solution

  • You need to have an overlay widget, i.e. a widget that covers the area of your main widget, but is above it. Then you implement paintEvent() in that overlay widget. See this question for more details.