Unsolved Suggestions for relevant key binding
-
I am not able to print ---- > I am here
-
Please suggest why
-
When I type Shift + tab is goes from item empty box to item2 label then item1 text box then item1 label
-
but my requirement is to
got back directtly from item2 text box to item1 text box
-
@Qt-Enthusiast There is no need to implement anything for switching focus via TAB/Shift-TAB - this should work without any code. In QtCreator/Designer you can specify the order in which Tab should got through the widgets.
-
My code is in pytqt and I have to go only to selected cells not all
-
@Qt-Enthusiast said in Suggestions for relevant key binding:
modifiers = QtGui.QApplication.keyboardModifiers()
# when the user presses Tab Key
# then the focus should go to prev text box
if ((modifiers & QtCore.Qt.ShiftModifier) and (event.key() == QtCore.Qt.Key_T)):
self.parent.focusPrevTextWidget()
returnif ((modifiers & QtCore.Qt.ShiftModifier) and (event.key() == QtCore.Qt.Key_Tab)): print("\m I am here") self.parent.focusPrevTextWidget()
Why
modifiers = QtGui.QApplication.keyboardModifiers()
# when the user presses Tab Key
# then the focus should go to prev text box
if ((modifiers & QtCore.Qt.ShiftModifier) and (event.key() == QtCore.Qt.Key_T)):
self.parent.focusPrevTextWidget()
returnif ((modifiers & QtCore.Qt.ShiftModifier) and (event.key() == QtCore.Qt.Key_Tab)): print("\m I am here") --------------------> I am not getting print here self.parent.focusPrevTextWidget()
-
@Qt-Enthusiast I don't know why.
But as I wrote before there is NO need to implement Shift-Tab as it should work out of the box. -
but I have to owerite then what shall I
modifiers = QtGui.QApplication.keyboardModifiers()
if ((modifiers & QtCore.Qt.ShiftModifier) and (event.key() == QtCore.Qt.Key_Tab)):
print("\m I am here") --------------------> I am not getting print here
self.parent.focusPrevTextWidget()how do I get print("\m I am here") ---when I press Shift + Key_tab
-
@Qt-Enthusiast said in Suggestions for relevant key binding:
but I have to owerite
Can you please explain why you think you have to?
If you want to change the order in which Tab/Shift-Tab navigates through widgets you can do it in Designer, or using https://doc.qt.io/qt-5/qwidget.html#setTabOrder in code. -
I want to skip some of cells for that I have to overwrite
-
@Qt-Enthusiast So, the ones you want to skip should never get focus? If so just use https://doc.qt.io/qt-5/qwidget.html#focusPolicy-prop
You can unset Qt::TabFocus, so it will not get focus via Tab.
Or Qt::NoFocus if it should never get focus. -
def setRowSequenceForTabKey(self):
# next row sequence
# when the user press tab key
# code is to get the next sequence
# this is predefined for each className
if self.className == "VerificationObjective":
self.row_sequence = [1,2,3,4,6]
else:
self.row_sequence = [1,2,4]rowCount = self.table.rowCount() for i in range(0, rowCount): if cellWidget or i in self.row_sequence: cellWidget.setFocusPolicy(QtCore.Qt.NoFocus)
The following code is not working
Could you please suggestion
-
@Qt-Enthusiast What is cellWidget here? You change the same cellWidget in the loop - I don't know how is this supposed to work? You should iterate over the cells and change their focus policy instead. Now you show that you're using a table. That is something you should have said straight from the beginning.
-
Can we check if the Widget type is QLineEdit ?
-
@Qt-Enthusiast said in Suggestions for relevant key binding:
Can we check if the Widget type is QLineEdit ?
Yes - but we're a Qt forum, no python for beginners forum. Sorry.
-
So I have QtableWidget
as show in pictuure
For Row 0
1 ) The first column of each row is QLablel
2 second colum is QlineditFor Row 1 to Row2
1 ) The first column of each row is QLablel
2 second colum is QLabelFor Row 3 to end
1 ) The first column of each row is QLablel
2 second column has QWidget that has QSplitter(Vertical)
First widget of spiltter has QLineEdit
Other widget of splitter has QLabe;My project is
When the user press KeyTab , the cursor should move from one QLineEdit to other Qlinedit ( it should not jump within the QLineEdit
Please suggest some generic way
For 3rd to last row the second column is Q![alt text](![image url]( image url))