[Qt-interest] [Fwd: Re: [Fwd: [Fwd: AW: [Fwd: [Fwd: Problem with focusNextChild andQPlainTextEdit]]]]]

Stefano Rosellini s.rosellini at iv-srl.it
Fri Mar 27 14:53:03 CET 2009


I found a solution.

If I call
  QWidget::focusNextPrevChild(true);
instead of
  focusNextChild();
it works well!


Stefano Rosellini
Informatica Valdinievole


-------- Messaggio Originale --------

Hi,

 > 1. Why if focusNextChild doesn't take care of scaling on parent widget?
 > If I press Tab on the last element of a widget, the focus is normally
 > recalculated scaling up to parent.

focusNextChild calls focusNextPrevChild(true) and if you look how that 
is implemented you will see it does march through the widget's parents 
as necessary. However, QAbstractScrollArea handles its scrollable widget 
through a viewport, and I am not sure if this is handled by 
QPlainTextEdit correctly for the simple reason that pressing the tab 
button doesn't (normally) change focus for that widget. I don't know for 
sure that this is the case, its just my guess.

 > 2. focusNextChild() is protected, so the only solutions seems to be the
 > parent subclassing. If the initiative is of Q(Simple)TextEdit, how can
 > set focus in general way indipendently from parent?

Passing the focus from the widget should be protected because it's up to 
the widget to decide when to do that. It wouldn't make much sense for 
another class to tell it to pass its focus to something else. Other 
classes can call setFocus if they need the focus.

If you want QSimpleTextEdit to behave differently, then you have to 
override it and modify its behaviour. That is the OOP method.

In any case it seems like focusNextChild shouldn't fail for QPlainTextEdit.

Cheers,
Ian.
_______________________________________________
Qt-interest mailing list
Qt-interest at trolltech.com
http://lists.trolltech.com/mailman/listinfo/qt-interest





More information about the Qt-interest-old mailing list