Nominate our 2022 Qt Champions!

Qpainter always print behind label

  • I have several labels on my screen(mainwindow.ui) And I need to draw on them. Unfortunately "Qpainter" just draws behind labels.

  • Looks like you paint on widget that contains these labels. And labels' paintEvents are called after your widget paintEvent.

  • how can i do that?? sorry i cant understand

  • Each widget (also a QLabel) has a background that is drawn onto the parent (e.g. your main window). You can reimplement each widgets paintEvent in a subclass and do your own painting there. If you overwrite the paintEvent of the main windwd, you draw behind each child, so behind the labels.

    If you want to change the labels, make a subclass of QLabel and use that instead of QLabel. Overwrite paintEvent in your QLabel subclass and draw there.

    If you want some main window image behind all labels, you could also make the labels transparent.

Log in to reply