PDA

View Full Version : How to check whether a widget is text-editable ???



wshn13
19th June 2012, 09:05
Now ,there is a widget (or qgraphicswidget ),is there some ways to check whether the widget is text-editable ???Thanks !

aamer4yu
19th June 2012, 10:31
You can use dynamic cast to check if the widget belongs to any of the text editable widgets like QLineEdit, QTextEdit , etc.
Hope this helps

wysota
19th June 2012, 10:38
Now ,there is a widget (or qgraphicswidget ),is there some ways to check whether the widget is text-editable ???Thanks !

Now or at all?

wshn13
20th June 2012, 02:39
You can use dynamic cast to check if the widget belongs to any of the text editable widgets like QLineEdit, QTextEdit , etc.
Hope this helps
Is there some common feature around the text editable widgets like QLineEdit, QTextEdit , etc ?

wysota
20th June 2012, 09:17
Yes, they tend to have focus. That's why I asked if you wanted to know whether some widget is a text widget at all or does it currently accept text. The latter can be checked by checking the focus, the former is basically not possible.

wshn13
21st June 2012, 04:00
Yes, they tend to have focus. That's why I asked if you wanted to know whether some widget is a text widget at all or does it currently accept text. The latter can be checked by checking the focus, the former is basically not possible.
The situation is that a widget has focus may not be text editable or inputable .Some widgets have focus may be text editable and may be not editable .

wysota
21st June 2012, 08:32
No, if a widget has keyboard focus, it accepts key events. That's the exact definition of focus.

amleto
21st June 2012, 10:00
e.g. buttons can get focus but aren't text-editable - perhaps that is the distinction the OP is trying to capture.

wysota
21st June 2012, 10:20
In that case it is not possible.

wshn13
25th June 2012, 02:20
e.g. buttons can get focus but aren't text-editable - perhaps that is the distinction the OP is trying to capture.
So the question is that I want to distinguish whether a foucsed widget is text-editable like qlineedit or not text-editable like button.

ChrisW67
25th June 2012, 04:19
You can tell a QLineEdit from a QPushButton in the manner that aamer4yu gave you in the first response.


QWidget *b = new QPushButton("Hello");
QWidget *m = new MyEdit;
QWidget *e = new QLineEdit;
QWidget *t = new QTextEdit;

if (qobject_cast<QLineEdit*>(b)) qDebug() << "b is-a QLineEdit";
if (qobject_cast<QLineEdit*>(e)) qDebug() << "e is-a QLineEdit";
if (qobject_cast<QLineEdit*>(m)) qDebug() << "m is-a QLineEdit";
if (qobject_cast<QLineEdit*>(t)) qDebug() << "t is-a QLineEdit";


Actually, the real question is why you want to do this? What are you trying to achieve?

wshn13
25th June 2012, 07:00
You can tell a QLineEdit from a QPushButton in the manner that aamer4yu gave you in the first response.


QWidget *b = new QPushButton("Hello");
QWidget *m = new MyEdit;
QWidget *e = new QLineEdit;
QWidget *t = new QTextEdit;

if (qobject_cast<QLineEdit*>(b)) qDebug() << "b is-a QLineEdit";
if (qobject_cast<QLineEdit*>(e)) qDebug() << "e is-a QLineEdit";
if (qobject_cast<QLineEdit*>(m)) qDebug() << "m is-a QLineEdit";
if (qobject_cast<QLineEdit*>(t)) qDebug() << "t is-a QLineEdit";


Actually, the real question is why you want to do this? What are you trying to achieve?
The reason is that when a foucus event come ,I want my custom input method popup if the focused widget is actually text-editable like qlineedit ,but if the focued widget is not actually text-editable the input method should not be popup .

wysota
25th June 2012, 08:41
Why don't you just provide an input method plugin (see QInputContextPlugin and family)?