How to make shapes created by QPainter visible permanently?

I made a plugin that allows adding layers. And I did it as a popup window

self.setWindowFlags(Qt.WindowStaysOnTopHint | Qt.FramelessWindowHint)

This window is a child to qwindow()

active_window = Krita.instance().activeWindow().qwindow()
self.popup.setParent(active_window )

I do paint shapes with paintEvent

    def paintEvent(self, event) -> None:

        painter = QPainter(self)
        for b in self.buttons:

The paint looks like this:

    def paint(self, painter):
        painter.fillPath(self.path, self.back_color) 
        painter.drawPixmap(self.icon_rect, self.icon)

However when I switch tabs (dockers) the shapes disappear.

Am I missing something? Or maybe I should connect to qwindow event when tabs changes to redesplay the popup?

Would appreciate any advice :slight_smile:

Seems like my pop just being placed below canvas:

Shouldn’t it be self.popup.setParent(active_window)?

It actually is (missed that part while transferring code)

Have to do self.raise_() on Popup widget on paintEvent() to bring my widget upfront of canvas.
Not sure if it is optimal solution though.

1 Like

This looks very similar to the plugin I have requested

Not exactly. This particular plugin allows you to create a new layers. I will post a release note in Plugins section in couple of days. :slight_smile:

The plugin you requested is a bit more trickier to develop.

1 Like

Turns out calling self.raise_() on every paintEvent pretty CPU heavy.
I would appretiate any other ideas how to prevent this particular behavior.

As noted before

self.setWindowFlags(Qt.WindowStaysOnTopHint | Qt.FramelessWindowHint)

Does not seem to work.

Thanks in advance :slight_smile:

Those are only window hint flags, they only take effect if you combine it with a window type flag (Window, Dialog, Popup etc.).

1 Like

I see.

Ended up creating special kind of function to track widget position in qwindow() children list.
A bit weird, though got rize_() being called only when children changed (which is very, very seldom).