如何浏览已禁用的QLineEdit小部件?

时间:2012-02-28 01:04:38

标签: qt navigation

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

QLineEdit a (enabled) -> QLineEdit b (enabled) -> QLineEdit c (disabled) -> QLineEdit d (disabled) -> QLineEdit e (enabled)

1 个答案:

答案 0 :(得分:1)

听起来你想使用QKeyEvents

简单的实现将是这样的:

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;
};

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