【问题标题】:How to navigate through disabled QLineEdit widgets?如何浏览禁用的 QLineEdit 小部件?
【发布时间】:2012-02-28 17:23:03
【问题描述】:

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

QLineEdit a(启用)-> QLineEdit b(启用)-> QLineEdit c(禁用)-> QLineEdit d(禁用)-> QLineEdit e(启用)

【问题讨论】:

  • 不是很清楚。您的意思是在使用选项卡浏览 QLineEdits 时?如果是这种情况,tab 顺序应该考虑到这一点。
  • 不是标签。通过箭头键导航。
  • 我建议不要这样做。在大多数情况下,操作系统已经通过 Tab 键提供了此功能。通过添加此内容,您可能会不必要地增加混乱。
  • 我想不出任何使用光标键在行编辑之间导航的 HIG 指南。

标签: qt navigation


【解决方案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;
};

当然,具体实施取决于您。

【讨论】:

  • 谢谢老兄。有了这种实现方式。
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 2013-04-07
  • 1970-01-01
  • 1970-01-01
  • 2021-12-28
  • 1970-01-01
  • 1970-01-01
  • 2011-02-01
相关资源
最近更新 更多