Qt 如何在禁用的QLineEdit小部件中导航?

Qt 如何在禁用的QLineEdit小部件中导航?,qt,navigation,Qt,Navigation,如果我有5个QLineEdit小部件。让用户能够在它们之间导航的最佳方式是什么(跳过任何禁用的) QLineEdit a(已启用)->QLineEdit b(已启用)->QLineEdit c(已禁用)->QLineEdit d(已禁用)->QLineEdit e(已启用) 听起来你想用 一个简单的实现是这样的: class MyClass : public QWidget { //whatever you want protected: //here, override the v

如果我有5个QLineEdit小部件。让用户能够在它们之间导航的最佳方式是什么(跳过任何禁用的)

QLineEdit a(已启用)->QLineEdit b(已启用)->QLineEdit c(已禁用)->QLineEdit d(已禁用)->QLineEdit e(已启用)
听起来你想用

一个简单的实现是这样的:

class MyClass : public QWidget
{
  //whatever you want
  protected:
  //here, override the virtual function keyPressEvent (from QWidget)
  void QWidget::keyPressEvent(QKeyEvent* ev)
  {
    //check for the key(s) you care about and handle the event if needed
    //by iterating through lineEditList, asking each QLineEdit* if 
    //the 'enabled' property is true.  When you find the appropriate one,
    //set the cursor to that widget.
  }
  QList<QLineEdit*> lineEditList;
  int currentLineEditIndex;
};
classmyclass:publicqwidget
{
//随便你
受保护的:
//在这里,覆盖虚拟函数keyPressEvent(来自QWidget)
无效QWidget::按键事件(QKeyEvent*ev)
{
//检查您关心的密钥,并在需要时处理事件
//通过迭代lineEditList,询问每个QLineEdit*是否
//“enabled”属性为true。找到合适的属性后,
//将光标设置到该小部件。
}
QList-lineEditList;
int currentLineEditIndex;
};

实施的具体细节当然取决于您。

还不是很清楚。您的意思是当使用选项卡在QLineEdits中导航时?如果是这样的话,制表符顺序应该注意这一点,而不是按制表符。通过箭头键导航。我建议不要这样做。在大多数情况下,操作系统已经通过Tab键提供了此功能。通过添加这一点,您可能会增加不必要的混乱。我想不出任何使用光标键在线条编辑之间导航的高指南。谢谢,老兄。这样的实现有点进展。
class MyClass : public QWidget
{
  //whatever you want
  protected:
  //here, override the virtual function keyPressEvent (from QWidget)
  void QWidget::keyPressEvent(QKeyEvent* ev)
  {
    //check for the key(s) you care about and handle the event if needed
    //by iterating through lineEditList, asking each QLineEdit* if 
    //the 'enabled' property is true.  When you find the appropriate one,
    //set the cursor to that widget.
  }
  QList<QLineEdit*> lineEditList;
  int currentLineEditIndex;
};