Results 1 to 8 of 8

Thread: Hide cursor of QLineEdit

  1. #1
    Join Date
    May 2013
    Posts
    321
    Thanks
    9
    Thanked 8 Times in 8 Posts
    Qt products
    Qt5
    Platforms
    MacOS X Unix/X11 Windows

    Default Hide cursor of QLineEdit

    Hi,
    Is it possible to hide the cursor of QLineEdit and show it when needed ?
    It's because I have a widget I would enable edit only when one click on it, readOnly works but it has problem with cursor when changing.
    Thanks

  2. #2
    Join Date
    Apr 2012
    Location
    India.
    Posts
    88
    Thanked 8 Times in 8 Posts
    Qt products
    Qt4 Qt5
    Platforms
    MacOS X Unix/X11 Windows

    Default Re: Hide cursor of QLineEdit

    You need to derive class from QLineEdit and in the following situation you should make the control read only.
    1. focusOutEvent.
    2. returnPressed signal.

    & on mouse click you can remove the read only status ...I think that is the behaviour you want...

  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: Hide cursor of QLineEdit

    Quote Originally Posted by Alundra View Post
    Hi,
    Is it possible to hide the cursor of QLineEdit and show it when needed ?
    It's because I have a widget I would enable edit only when one click on it, readOnly works but it has problem with cursor when changing.
    Thanks
    What problems does "readOnly" have with the cursor?
    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
    May 2013
    Posts
    321
    Thanks
    9
    Thanked 8 Times in 8 Posts
    Qt products
    Qt5
    Platforms
    MacOS X Unix/X11 Windows

    Default Re: Hide cursor of QLineEdit

    https://bugreports.qt-project.org/browse/QTBUG-37686
    this problem, it's my bug report.

  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: Hide cursor of QLineEdit

    If you want the widget to have keyboard focus after being double-clicked then set focus on it there. I don't see any Qt bug there. I also don't understand what you are trying to do. You don't have to manipulate "readOnly" property to make a widget gain or lose 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.


  6. #6
    Join Date
    May 2013
    Posts
    321
    Thanks
    9
    Thanked 8 Times in 8 Posts
    Qt products
    Qt5
    Platforms
    MacOS X Unix/X11 Windows

    Default Re: Hide cursor of QLineEdit

    The problem is the cursor is not visible and using setFocus() that doesn't show it too, you can try the code I have write in the BugReport, that show the problem.
    To have the cursor visible, when double click (on the sample of the bug report), you have to use keyboard, only when you use keyboard the cursor is visible again.

  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: Hide cursor of QLineEdit

    Quote Originally Posted by Alundra View Post
    The problem is the cursor is not visible and using setFocus() that doesn't show it too, you can try the code I have write in the BugReport, that show the problem.
    To have the cursor visible, when double click (on the sample of the bug report), you have to use keyboard, only when you use keyboard the cursor is visible again.
    As I said your test report is broken, at least when using Qt4.

    I don't have any problems with the cursor using the following code:

    Qt Code:
    1. #include <QtGui>
    2.  
    3. class LineEdit : public QLineEdit {
    4. Q_OBJECT
    5. public:
    6. LineEdit(QWidget *parent = 0) : QLineEdit(parent) { setReadOnly(true); }
    7. protected:
    8. void mouseDoubleClickEvent(QMouseEvent *) {
    9. setReadOnly(false);
    10. setFocus();
    11. activateWindow();
    12. }
    13. };
    14.  
    15. #include "main.moc"
    16.  
    17. int main(int argc, char **argv) {
    18. QApplication app(argc, argv);
    19. LineEdit le;
    20. le.show();
    21. le.setText("ABC");
    22. return app.exec();
    23. }
    To copy to clipboard, switch view to plain text mode 

    Still, the real question is why do you want to use "readOnly" here? You don't need to mark a widget read-only to not see the cursor. Just focus-out of the widget and/or don't accept focus in situations when you don't want to. Maybe you just need to change the focus policy (e.g. to Qt::ClickFocus)?
    Last edited by wysota; 3rd June 2014 at 14:28.
    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
    May 2013
    Posts
    321
    Thanks
    9
    Thanked 8 Times in 8 Posts
    Qt products
    Qt5
    Platforms
    MacOS X Unix/X11 Windows

    Default Re: Hide cursor of QLineEdit

    Using Qt4 the problem is not there :
    http://www.qtcentre.org/threads/5848...658#post260658
    Qt::ClickFocus is maybe the good way to go here, I will try it.

Similar Threads

  1. QLineEdit cursor not vissible or blocked
    By Alundra in forum Qt Programming
    Replies: 14
    Last Post: 20th October 2017, 16:00
  2. set cursor position in qlineedit with an inputmask
    By guitar1 in forum Qt Programming
    Replies: 2
    Last Post: 11th March 2011, 17:13
  3. QLineEdit keep cursor active.
    By bunjee in forum Qt Programming
    Replies: 10
    Last Post: 2nd September 2009, 14:50
  4. How to Disable or hide cursor from QWidget?
    By ashukla in forum Qt Programming
    Replies: 5
    Last Post: 17th October 2007, 14:42
  5. How to hide mouse cursor
    By kiransu123 in forum Qt Programming
    Replies: 1
    Last Post: 23rd March 2007, 17:52

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.