0
如果我有5個QLineEdit小部件排隊。讓用戶在他們之間導航的最佳方式是什麼(跳過任何被禁用的)?如何瀏覽已禁用的QLineEdit小部件?
QLineEdit a (enabled) -> QLineEdit b (enabled) -> QLineEdit c (disabled) -> QLineEdit d (disabled) -> QLineEdit e (enabled)
如果我有5個QLineEdit小部件排隊。讓用戶在他們之間導航的最佳方式是什麼(跳過任何被禁用的)?如何瀏覽已禁用的QLineEdit小部件?
QLineEdit a (enabled) -> QLineEdit b (enabled) -> QLineEdit c (disabled) -> QLineEdit d (disabled) -> QLineEdit e (enabled)
聽起來像要使用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;
};
實施的細節是你的,當然。
謝謝老兄。通過這種實現獲得了一些進展。 – 2012-02-28 07:30:02
這不是很清楚。你是否指使用標籤瀏覽QLineEdits?如果是這種情況,那麼Tab鍵順序應該照顧。 – Correa 2012-02-28 01:37:54
不是通過製表符。通過箭頭鍵導航。 – 2012-02-28 02:08:53
我會建議不要這樣做。在大多數情況下,操作系統已經使用Tab鍵提供此功能。通過添加這個,你可能會增加不必要的混淆。 – 2012-02-28 08:32:21