Results 1 to 15 of 15

Thread: QLineEdit cursor not vissible or blocked

  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 QLineEdit cursor not vissible or blocked

    Hi all,
    I have a custom Line editor who act as SliderLineEdit (like a spinbox horizontal without button).
    All works fine but on the double click event I change ReadOnly to false to allow to edit value by hand and here comes the problem.
    The problem is the text cursor is not visible until I use an arrow key (left or right) or I put a value by key.
    Here the code of the double click event :
    Qt Code:
    1. void CDoubleSliderLineEdit::mouseDoubleClickEvent( QMouseEvent* event )
    2. {
    3. // Check if we are in read-only mode.
    4. if( isReadOnly() )
    5. {
    6. // Change states.
    7. setReadOnly( false );
    8. m_SliderMode = false;
    9.  
    10. // Restore override cursor.
    11. QApplication::restoreOverrideCursor();
    12. }
    13. else
    14. {
    15. // Base class.
    16. QLineEdit::mouseDoubleClickEvent( event );
    17. }
    18. }
    To copy to clipboard, switch view to plain text mode 
    I have to add m_SliderMode = false;, without it it's blocked like one mouse pressed but never released.
    Thanks for the help

  2. #2
    Join Date
    Jan 2006
    Location
    Graz, Austria
    Posts
    8,416
    Thanks
    37
    Thanked 1,544 Times in 1,494 Posts
    Qt products
    Qt3 Qt4 Qt5
    Platforms
    Unix/X11 Windows

    Default Re: QLineEdit cursor not vissible or blocked

    You probably have to set the focus, see QWidget::setFocus()

    Cheers,
    _

  3. #3
    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: QLineEdit cursor not vissible or blocked

    I have tried to add setFocus() at the end of mouseDoubleClickEvent, the result is the same.

  4. #4
    Join Date
    Jan 2006
    Location
    Graz, Austria
    Posts
    8,416
    Thanks
    37
    Thanked 1,544 Times in 1,494 Posts
    Qt products
    Qt3 Qt4 Qt5
    Platforms
    Unix/X11 Windows

    Default Re: QLineEdit cursor not vissible or blocked

    Hmm, no idea. Can you post or attach the code of your slider?

    Cheers,
    _

  5. #5
    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: QLineEdit cursor not vissible or blocked

    Here a minimal code who reproduce the issue and can be compiled easy.
    The code contains a QVBoxLayout to switch because when the CustomLineEdit lost focus he changes his state.
    By default the CustomLineEdit is on read-only and waits a double click to change value.
    Qt Code:
    1. #include <QApplication>
    2. #include <QMainWindow>
    3. #include <QLineEdit>
    4. #include <QVBoxLayout>
    5.  
    6. class CustomLineEdit : public QLineEdit
    7. {
    8. public:
    9.  
    10. CustomLineEdit(QWidget* parent = 0) :
    11. QLineEdit(parent)
    12. {
    13. setReadOnly(true);
    14. setText("0.00");
    15. }
    16.  
    17. protected:
    18.  
    19. virtual void focusOutEvent(QFocusEvent* event)
    20. {
    21. QLineEdit::focusOutEvent(event);
    22. setReadOnly(true);
    23. deselect();
    24. }
    25.  
    26. virtual void mouseDoubleClickEvent(QMouseEvent* event)
    27. {
    28. if(isReadOnly())
    29. setReadOnly(false);
    30. else
    31. QLineEdit::mouseDoubleClickEvent(event);
    32. }
    33. };
    34.  
    35. class MainWindow : public QMainWindow
    36. {
    37. public:
    38.  
    39. MainWindow(QWidget* parent = 0) :
    40. QMainWindow(parent)
    41. {
    42. QVBoxLayout* Layout = new QVBoxLayout;
    43. Layout->addWidget(new QLineEdit);
    44. Layout->addWidget(new CustomLineEdit);
    45. QWidget* Widget = new QWidget(this);
    46. Widget->setLayout(Layout);
    47. setCentralWidget(Widget);
    48. }
    49. };
    50.  
    51. int main(int argc, char *argv[])
    52. {
    53. QApplication a(argc, argv);
    54. MainWindow w;
    55. w.show();
    56. return a.exec();
    57. }
    To copy to clipboard, switch view to plain text mode 

  6. #6
    Join Date
    Jan 2006
    Location
    Graz, Austria
    Posts
    8,416
    Thanks
    37
    Thanked 1,544 Times in 1,494 Posts
    Qt products
    Qt3 Qt4 Qt5
    Platforms
    Unix/X11 Windows

    Default Re: QLineEdit cursor not vissible or blocked

    Indeed, very strange.

    Interestingly it works with Qt4.

    Cheers,
    _

  7. #7
    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: QLineEdit cursor not vissible or blocked

    Is it possible to have a fix for QT 5.3 ?
    Thanks

  8. #8
    Join Date
    Jan 2006
    Location
    Graz, Austria
    Posts
    8,416
    Thanks
    37
    Thanked 1,544 Times in 1,494 Posts
    Qt products
    Qt3 Qt4 Qt5
    Platforms
    Unix/X11 Windows

    Default Re: QLineEdit cursor not vissible or blocked

    If someone finds the issue and submits a fix via the qt-project.org workflow then yes, it can be in 5.3

    Cheers,
    _

  9. #9
    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: QLineEdit cursor not vissible or blocked

    Quote Originally Posted by anda_skoa View Post
    If someone finds the issue and submits a fix via the qt-project.org workflow then yes, it can be in 5.3

    Cheers,
    _
    Ok that mean no fix will be there for a long time I think.

  10. #10
    Join Date
    Jan 2006
    Location
    Graz, Austria
    Posts
    8,416
    Thanks
    37
    Thanked 1,544 Times in 1,494 Posts
    Qt products
    Qt3 Qt4 Qt5
    Platforms
    Unix/X11 Windows

    Default Re: QLineEdit cursor not vissible or blocked

    How can you tell?

    Did you get a reponse in that direction on your bug report?
    Have you reported the issue or checked if someone else already has?

    Cheers,
    _

  11. #11
    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: QLineEdit cursor not vissible or blocked

    it's called experience

  12. #12
    Join Date
    Jan 2006
    Location
    Graz, Austria
    Posts
    8,416
    Thanks
    37
    Thanked 1,544 Times in 1,494 Posts
    Qt products
    Qt3 Qt4 Qt5
    Platforms
    Unix/X11 Windows

    Default Re: QLineEdit cursor not vissible or blocked

    Your experience tells you that unreported bugs take a long to get fixed?

    Cheers,
    _

  13. #13
    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: QLineEdit cursor not vissible or blocked

    i'm not the only one to say that, but it's not very important on this case because this one is not a BIG bug.

  14. #14
    Join Date
    Oct 2017
    Posts
    1
    Qt products
    Qt5
    Platforms
    Windows

    Default Re: QLineEdit cursor not vissible or blocked

    I found this bug still exists in Qt 5.6.3 and I came up with a workaround. Here it is, in case anyone needs it:

    Qt Code:
    1. //--------------------------------------------------------
    2. void QActivatableLineEdit::mousePressEvent(QMouseEvent* e)
    3. {
    4. if (isReadOnly() == false)
    5. {
    6. QLineEdit::mousePressEvent(e);
    7. return;
    8. }
    9.  
    10. QLineEdit::setReadOnly(false);
    11. QLineEdit::mousePressEvent(e);
    12.  
    13. // Qt5 bug! The cursor is not shown!
    14. int cp = cursorPositionAt(e->pos());
    15. QApplication::postEvent(this, new QKeyEvent(QEvent::KeyPress, Qt::Key_Right, Qt::NoModifier));
    16. QApplication::postEvent(this, new QKeyEvent(QEvent::KeyRelease, Qt::Key_Right, Qt::NoModifier));
    17. QApplication::processEvents();
    18. setCursorPosition(cp);
    19. }
    To copy to clipboard, switch view to plain text mode 
    Last edited by fabrizio.benedetti; 13th October 2017 at 10:26.

  15. #15
    Join Date
    Oct 2017
    Posts
    4
    Thanked 1 Time in 1 Post
    Qt products
    Qt5
    Platforms
    Unix/X11 Windows Android

    Default Re: QLineEdit cursor not vissible or blocked

    As a trick:

    Qt Code:
    1. if(isReadOnly()){
    2. setReadOnly(false);
    3. setSelection(text().length(), text().length() + 1);
    4. }
    To copy to clipboard, switch view to plain text mode 

Similar Threads

  1. Replies: 2
    Last Post: 10th May 2013, 06:20
  2. QLineEdit cursor lost when switching between layouts
    By missoni in forum Qt Programming
    Replies: 1
    Last Post: 6th April 2011, 12:48
  3. set cursor position in qlineedit with an inputmask
    By guitar1 in forum Qt Programming
    Replies: 2
    Last Post: 11th March 2011, 17:13
  4. Replies: 2
    Last Post: 25th November 2010, 09:53
  5. QLineEdit keep cursor active.
    By bunjee in forum Qt Programming
    Replies: 10
    Last Post: 2nd September 2009, 14:50

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.