How get QtabBar object from docked widget?

I’m developing a plugin.It is possible to quickly make any docker appear under the mouse.But it can’t remember the position of tabs.
Just like this:
动画
Docker was previously displayed in the panel, after finishing floating and docked I want it to still display, instead of being hidden.

QTabBar.cureentIndex

Changing this property can modify the displayed tabs, but I can’t find a way to get QTabBar object.
If you know how to fix it please tell me.

1 Like

QWidget.raise_() works with QTabBar tabs, simply just raise widget at tab to make tab current.

from krita import (
        Krita,)

from PyQt5.QtGui import (
        QCursor,)
                         

def floatify_docker(docker_name):
    app = Krita.instance()
    docker = next((d for d in app.dockers() if d.objectName() == docker_name), None)
    
    docker.setFloating(True)
    docker.move(QCursor.pos())
    docker.setVisible(True)
    docker.raise_()  # raise docker above other windows


def unfloatify_docker(docker_name):
    app = Krita.instance()
    docker = next((d for d in app.dockers() if d.objectName() == docker_name), None)

    docker.setFloating(False)
    docker.raise_()  # raise docker above other tabs


# testing
from PyQt5.QtCore import (
        QTimer,)


def print_docker_info():
    app = Krita.instance()
    for d in app.dockers():
        print(f'docker name = "{d.objectName()}"\n'
              f'docker title = "{d.windowTitle()}"\n'
              f'is floating = {d.isFloating()}\n'
              f'is visible = {d.isVisible()}\n')

# print names of all dockers
print_docker_info()

# floatify SpecificColorSelector
floatify_docker('SpecificColorSelector')

# 5000 milliseconds later, unfloatify SpecificColorSelector
QTimer.singleShot(5000, lambda : unfloatify_docker('SpecificColorSelector'))

/AkiR

2 Likes

This is very useful. Seeing Shade maker plugin appear near mouse would be great.

1 Like

you can grab the child widget of the docker rather than the qdockwidget itself. this will leave the tabs alone.

This is good, thank your code.

1 Like

I’ll give it a try

This is very useful. Seeing Shade maker plugin appear near mouse would be great.

Thanks for mentioning this, it seems feasible. I’ll keep it in mind for the next update!

Additionally, perhaps @Aqao 's solution will also be useful to you.

1 Like