how to synchronize timeline's vertical header

On timelinedocker, I often get confused about which layer I am drawing.
so I wouid like to synchronize the row of the timeline’vertical header with the tableview of the timeline’s row.
(I would like to synchronize the active layer when I click on a cell in the timeline. )
Here is what I wrote.

from krita import *
from PyQt5.QtWidgets import *
from PyQt5.QtCore import *
from PyQt5.QtGui import *

qw = Krita.instance().activeWindow().qwindow()
timeline_docker = qw.findChild(QDockWidget, "TimelineDocker")
table = next(c for c in timeline.findChildren(QWidget) if c.metaObject().className() == "TimelineFramesView")
def update_left_header():
    left_header = next(c for c in timeline_docker.findChildren(QWidget) if c.metaObject().className() == "TimelineLayersHeader")
    left_header_data = table.verticalHeader().model().headerData(table.selectionModel().currentIndex().row(), table.verticalHeader().orientation())
    doc = Krita.instance().activeDocument()


krita version: 4.48
It seems to work, but I’m not sure if it’s right. I am beginner of coding. If you see any mistakes, please point them out.
Also, the above code gives me an error in the 5.0beta. I hope you can tell me how to fix it.
[deepL translate]

This is my first post. If something wrong with my posting, please forgive me.

What is the error that you get?

but here changes that I would do. (NOT tested on Krita5)

from krita import *
from PyQt5.QtWidgets import *
from PyQt5.QtCore import *
from PyQt5.QtGui import *

def on_current_changed(current, previous):
    # Issue: selecting layers by name breaks down, if there are multiple layers with identical names.
    if current.isValid():
        layer_name =
        doc = Application.activeDocument()

q_win = Application.activeWindow().qwindow()
timeline_docker = q_win.findChild(QDockWidget, 'TimelineDocker')
table_view = next(c for c in timeline_docker.findChildren(QTableView) if c.metaObject().className() == 'TimelineFramesView')


Thank you for the reply and the sample code.

I don’t understand most of that part, so I’ll read Qt documentation carefully.
The error in the 5.0Beta version on krita’s scripter is

In file:
In function: at line:8.Line with error:

in the part(table=next(c for c in timeline.findChidren…)

I couldn’t immediately think of a way to deal with the same layer name, so I decided to add a sequential number after the name to handle it using "collections.Counter()"method. And I’ll put the Beta version on hold for now. Thanks for the advice!