Pages

Showing posts with label QtQuick. Show all posts
Showing posts with label QtQuick. Show all posts

Friday, August 7, 2020

Qt Quick Controls: currentIndex won't change if model is statically generated on Tumbler + workaround

After a long time I reported a bug to Qt as I found quite unexpected bug from Qt Quick. On Qt Quick Controls 2, if you set model statically in Tumbler component(e.g. model: [2, 4, 6, 7, 10]), everything is shown properly but currentIndex doesn't change at all. For example, even though the screen shows the fifth item, currentIndex is still 0, and onCurrentIndexChanged event doesn't fire at all.

To work around this bug, you may just set a model "dynamically" like as follows:

Components.onCompleted: {
     // do something
     model=[ 1, 2, 3, 4, 5 ]
     // do something more
}

My check indicates this bug existed since Qt 5.12 or earlier, but nobody seems to have reported this, though I think there must be people using Tumbler like I do...... Well, maybe everyone was too lazy to write a report.

Anyway I reported the bug, and got ticket number QTBUG-85933.
https://bugreports.qt.io/browse/QTBUG-85933

 I hope that the bug can be fixed sooner.

Qt Quick Controls: Tumbler에 model을 정적으로 생성하면 currentIndex가 변경되지 않는 문제+우회방안

오랜만에 Qt 버그리포트를 하나 작성했습니다. Qt Quick에서 황당한 버그가 하나 있더군요. Quick Controls 2의 Tumbler에서 model을 정적으로 미리 설정해 두면(이를테면 model: [2, 4, 6, 8, 10]같은 형태로......) 화면은 제대로 작동하는데 내부에서 자기가 어느 데이터를 가리키고 있는지를 찾지 못하는 문제가 있습니다. currentIndex가 죽었다 깨나도 안 변하더군요. 분명히 화면은 다섯번째 아이템을 가리키고 있는데, currentIndex는 0으로 그대로이고, onCurrentIndexChanged 이벤트도 발생을 하지 않는다거나 하는 문제가 있습니다.

이 문제를 우회하려면, model을 동적으로 넣어주면 됩니다. 이를테면 이런 식으로요:

Components.onCompleted: {
// do something
model=[ 1, 2, 3, 4, 5 ]
// do something more
}

확인해보니 최소한 Qt 5.12부터 있던 버그인데, 아무도 신고하지 않은 것 같더군요. 분명 저처럼 쓸 일이 다들 있을 것 같기도 한데 말이죠...... 아니면, 어쩌면 다들 귀찮아서 말았을지도 모르겠네요. 

하여간 신고했고, 티켓 QTBUG-85933를 받았습니다.
https://bugreports.qt.io/browse/QTBUG-85933

이 버그는 언제쯤 해결될 수 있을지 모르겠네요.

Thursday, January 18, 2018

If your control can't fetch keyboard focus in Qt Quick......

Use forceActiveFocus() method.

To get the keyboard focus, you have to set focus:true from the very root of all visual parents the control is attached. If the structure becomes complicated, you have no idea on where to "power on" and where not. In that case, use forceActiveFocus() to make any necessary attribute changes at once.

Man I had to throw away yesterday not knowing this. OTL

Qt Quick에서 뭔 짓을 해도 컨트롤이 키보드 포커스를 가져오지 못한다면......

forceActiveFocus() method를 사용하면 됩니다.

원래 키보드 포커스는 visual parent에서 해당 컨트롤의 모든 부모계통 컨트롤이 속성을 focus: true로 놓도록 설정되어야 잡히는데, 구조가 복잡해지면 어느게 어느거고 어떻게 영향을 받는지 감이 안 잡히는 상황이 발생합니다. 이때 forceActiveFocus()를 사용하면 필요한 부분을 다 알아서 자동으로 바꿔줍니다.

......이거 몰라서 어제 하루 날려먹었네요. OTL