Results 1 to 13 of 13

Thread: How to check whether a widget is text-editable ???

  1. #1
    Join Date
    Jun 2011
    Posts
    45
    Thanks
    2
    Qt products
    Qt4
    Platforms
    Unix/X11

    Default How to check whether a widget is text-editable ???

    Now ,there is a widget (or qgraphicswidget ),is there some ways to check whether the widget is text-editable ???Thanks !

  2. #2
    Join Date
    Oct 2006
    Location
    New Delhi, India
    Posts
    2,467
    Thanks
    8
    Thanked 334 Times in 317 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: How to check whether a widget is text-editable ???

    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

  3. #3
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,359
    Thanks
    3
    Thanked 5,015 Times in 4,792 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: How to check whether a widget is text-editable ???

    Quote Originally Posted by wshn13 View Post
    Now ,there is a widget (or qgraphicswidget ),is there some ways to check whether the widget is text-editable ???Thanks !
    Now or at all?
    Your biological and technological distinctiveness will be added to our own. Resistance is futile.

    Please ask Qt related questions on the forum and not using private messages or visitor messages.


  4. #4
    Join Date
    Jun 2011
    Posts
    45
    Thanks
    2
    Qt products
    Qt4
    Platforms
    Unix/X11

    Default Re: How to check whether a widget is text-editable ???

    Quote Originally Posted by aamer4yu View Post
    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 ?

  5. #5
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,359
    Thanks
    3
    Thanked 5,015 Times in 4,792 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: How to check whether a widget is text-editable ???

    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.
    Your biological and technological distinctiveness will be added to our own. Resistance is futile.

    Please ask Qt related questions on the forum and not using private messages or visitor messages.


  6. #6
    Join Date
    Jun 2011
    Posts
    45
    Thanks
    2
    Qt products
    Qt4
    Platforms
    Unix/X11

    Default Re: How to check whether a widget is text-editable ???

    Quote Originally Posted by wysota View Post
    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 .

  7. #7
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,359
    Thanks
    3
    Thanked 5,015 Times in 4,792 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: How to check whether a widget is text-editable ???

    No, if a widget has keyboard focus, it accepts key events. That's the exact definition of focus.
    Your biological and technological distinctiveness will be added to our own. Resistance is futile.

    Please ask Qt related questions on the forum and not using private messages or visitor messages.


  8. #8
    Join Date
    Sep 2011
    Posts
    1,241
    Thanks
    3
    Thanked 127 Times in 126 Posts
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: How to check whether a widget is text-editable ???

    e.g. buttons can get focus but aren't text-editable - perhaps that is the distinction the OP is trying to capture.
    If you have a problem, CUT and PASTE your code. Do not retype or simplify it. Give a COMPLETE and COMPILABLE example of your problem. Otherwise we are all guessing the problem from a fabrication where relevant details are often missing.

  9. #9
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,359
    Thanks
    3
    Thanked 5,015 Times in 4,792 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: How to check whether a widget is text-editable ???

    In that case it is not possible.
    Your biological and technological distinctiveness will be added to our own. Resistance is futile.

    Please ask Qt related questions on the forum and not using private messages or visitor messages.


  10. #10
    Join Date
    Jun 2011
    Posts
    45
    Thanks
    2
    Qt products
    Qt4
    Platforms
    Unix/X11

    Default Re: How to check whether a widget is text-editable ???

    Quote Originally Posted by amleto View Post
    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.

  11. #11
    Join Date
    Mar 2009
    Location
    Brisbane, Australia
    Posts
    7,729
    Thanks
    13
    Thanked 1,610 Times in 1,537 Posts
    Qt products
    Qt4 Qt5
    Platforms
    Unix/X11 Windows
    Wiki edits
    17

    Default Re: How to check whether a widget is text-editable ???

    You can tell a QLineEdit from a QPushButton in the manner that aamer4yu gave you in the first response.
    Qt Code:
    1. QWidget *b = new QPushButton("Hello");
    2. QWidget *m = new MyEdit;
    3. QWidget *e = new QLineEdit;
    4. QWidget *t = new QTextEdit;
    5.  
    6. if (qobject_cast<QLineEdit*>(b)) qDebug() << "b is-a QLineEdit";
    7. if (qobject_cast<QLineEdit*>(e)) qDebug() << "e is-a QLineEdit";
    8. if (qobject_cast<QLineEdit*>(m)) qDebug() << "m is-a QLineEdit";
    9. if (qobject_cast<QLineEdit*>(t)) qDebug() << "t is-a QLineEdit";
    To copy to clipboard, switch view to plain text mode 

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

  12. #12
    Join Date
    Jun 2011
    Posts
    45
    Thanks
    2
    Qt products
    Qt4
    Platforms
    Unix/X11

    Default Re: How to check whether a widget is text-editable ???

    Quote Originally Posted by ChrisW67 View Post
    You can tell a QLineEdit from a QPushButton in the manner that aamer4yu gave you in the first response.
    Qt Code:
    1. QWidget *b = new QPushButton("Hello");
    2. QWidget *m = new MyEdit;
    3. QWidget *e = new QLineEdit;
    4. QWidget *t = new QTextEdit;
    5.  
    6. if (qobject_cast<QLineEdit*>(b)) qDebug() << "b is-a QLineEdit";
    7. if (qobject_cast<QLineEdit*>(e)) qDebug() << "e is-a QLineEdit";
    8. if (qobject_cast<QLineEdit*>(m)) qDebug() << "m is-a QLineEdit";
    9. if (qobject_cast<QLineEdit*>(t)) qDebug() << "t is-a QLineEdit";
    To copy to clipboard, switch view to plain text mode 

    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 .

  13. #13
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,359
    Thanks
    3
    Thanked 5,015 Times in 4,792 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: How to check whether a widget is text-editable ???

    Why don't you just provide an input method plugin (see QInputContextPlugin and family)?
    Your biological and technological distinctiveness will be added to our own. Resistance is futile.

    Please ask Qt related questions on the forum and not using private messages or visitor messages.


Similar Threads

  1. Contoured text in editable QGraphicsTextItem
    By stampede in forum Qt Programming
    Replies: 4
    Last Post: 8th November 2011, 23:22
  2. Replies: 0
    Last Post: 22nd May 2011, 22:34
  3. how can I make a balloon to wrap the editable text?
    By learning_qt in forum Qt Programming
    Replies: 9
    Last Post: 20th January 2009, 15:09
  4. Editable text in QGraphicsView
    By wysota in forum Qt Programming
    Replies: 8
    Last Post: 24th February 2007, 15:30
  5. make each row of table widget not editable??
    By darpan in forum Qt Programming
    Replies: 4
    Last Post: 16th October 2006, 10:22

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Digia, Qt and their respective logos are trademarks of Digia Plc in Finland and/or other countries worldwide.