python - PyQt: tab order not working for a simple custom widget -


i have made custom widget consisting of spinbox , checkbox. widget delegates focus spinbox using setfocusproxy. checkbox should not focus.

my problem when use widget in layout, qt tab order not work expected. below minimal working example. in example, focus should move var 1->var 3->var 2->var 4 when pressing tab key, doesn't.

if replace checkspinboxes regular qt widgets (e.g. qcheckboxes), works expected. using checkbox focus proxy seems make tab order work properly. problem seems using spinbox focus proxy.

from pyqt4 import qtgui, uic, qtcore import sys  class checkspinbox(qtgui.qwidget):      def __init__(self, parent=none, label=none):         super(self.__class__, self).__init__(parent)         self.degspinbox = qtgui.qspinbox()         self.normalcheckbox = qtgui.qcheckbox(label)         layout = qtgui.qhboxlayout(self)         layout.addwidget(self.degspinbox)         layout.addwidget(self.normalcheckbox)         self.degspinbox.setfocuspolicy(qtcore.qt.strongfocus)         self.normalcheckbox.setfocuspolicy(qtcore.qt.nofocus)         self.setfocuspolicy(qtcore.qt.strongfocus)         self.setfocusproxy(self.degspinbox)  class entryapp(qtgui.qwidget):      def __init__(self):         super(self.__class__, self).__init__()         layout = qtgui.qgridlayout()         self.sp1 = checkspinbox(label='var 1')         self.sp2 = checkspinbox(label='var 2')         self.sp3 = checkspinbox(label='var 3')         self.sp4 = checkspinbox(label='var 4')                  layout.addwidget(self.sp1,1,1)         layout.addwidget(self.sp2,1,2)         layout.addwidget(self.sp3,2,1)         layout.addwidget(self.sp4,2,2)          self.setlayout(layout)          self.settaborder(self.sp1, self.sp3)         self.settaborder(self.sp3, self.sp2)         self.settaborder(self.sp2, self.sp4)  def main():     app = qtgui.qapplication(sys.argv)     eapp = entryapp()      eapp.show()     app.exec_()  if __name__ == '__main__':     main() 

ok, seems rather longstanding qt bug, settaborder() not handle widgets focus proxy. bug report in https://bugreports.qt.io/browse/qtbug-10907

simplest workaround (at least case above): explicitly put focus proxy on tab order chain, so: self.settaborder(self.sp1.focusproxy(), self.sp3.focusproxy())


Comments

Popular posts from this blog

java - Run spring boot application error: Cannot instantiate interface org.springframework.context.ApplicationListener -

reactjs - React router and this.props.children - how to pass state to this.props.children -

Excel VBA "Microsoft Windows Common Controls 6.0 (SP6)" Location Changes -