View Full Version : QLineEdit cursor not vissible or blocked
Alundra
18th March 2014, 17:12
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 :
void CDoubleSliderLineEdit::mouseDoubleClickEvent( QMouseEvent* event )
{
// Check if we are in read-only mode.
if( isReadOnly() )
{
// Change states.
setReadOnly( false );
m_SliderMode = false;
// Restore override cursor.
QApplication::restoreOverrideCursor();
}
else
{
// Base class.
QLineEdit::mouseDoubleClickEvent( event );
}
}
I have to add m_SliderMode = false;, without it it's blocked like one mouse pressed but never released.
Thanks for the help
anda_skoa
18th March 2014, 18:55
You probably have to set the focus, see QWidget::setFocus()
Cheers,
_
Alundra
18th March 2014, 19:25
I have tried to add setFocus() at the end of mouseDoubleClickEvent, the result is the same.
anda_skoa
19th March 2014, 08:45
Hmm, no idea. Can you post or attach the code of your slider?
Cheers,
_
Alundra
19th March 2014, 13:08
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.
#include <QApplication>
#include <QMainWindow>
#include <QLineEdit>
#include <QVBoxLayout>
class CustomLineEdit : public QLineEdit
{
public:
CustomLineEdit(QWidget* parent = 0) :
QLineEdit(parent)
{
setReadOnly(true);
setText("0.00");
}
protected:
virtual void focusOutEvent(QFocusEvent* event)
{
QLineEdit::focusOutEvent(event);
setReadOnly(true);
deselect();
}
virtual void mouseDoubleClickEvent(QMouseEvent* event)
{
if(isReadOnly())
setReadOnly(false);
else
QLineEdit::mouseDoubleClickEvent(event);
}
};
class MainWindow : public QMainWindow
{
public:
MainWindow(QWidget* parent = 0) :
QMainWindow(parent)
{
QVBoxLayout* Layout = new QVBoxLayout;
Layout->addWidget(new QLineEdit);
Layout->addWidget(new CustomLineEdit);
QWidget* Widget = new QWidget(this);
Widget->setLayout(Layout);
setCentralWidget(Widget);
}
};
int main(int argc, char *argv[])
{
QApplication a(argc, argv);
MainWindow w;
w.show();
return a.exec();
}
anda_skoa
19th March 2014, 13:40
Indeed, very strange.
Interestingly it works with Qt4.
Cheers,
_
Alundra
19th March 2014, 16:38
Is it possible to have a fix for QT 5.3 ?
Thanks
anda_skoa
20th March 2014, 09:07
If someone finds the issue and submits a fix via the qt-project.org workflow then yes, it can be in 5.3
Cheers,
_
Alundra
20th March 2014, 19:17
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.
anda_skoa
21st March 2014, 09:26
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,
_
Alundra
22nd March 2014, 15:13
it's called experience :)
anda_skoa
22nd March 2014, 15:53
Your experience tells you that unreported bugs take a long to get fixed?
Cheers,
_
Alundra
23rd March 2014, 02:15
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.
fabrizio.benedetti
13th October 2017, 10:19
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:
//--------------------------------------------------------
void QActivatableLineEdit::mousePressEvent(QMouseEvent* e)
{
if (isReadOnly() == false)
{
QLineEdit::mousePressEvent(e);
return;
}
QLineEdit::setReadOnly(false);
QLineEdit::mousePressEvent(e);
// Qt5 bug! The cursor is not shown!
int cp = cursorPositionAt(e->pos());
QApplication::postEvent(this, new QKeyEvent(QEvent::KeyPress, Qt::Key_Right, Qt::NoModifier));
QApplication::postEvent(this, new QKeyEvent(QEvent::KeyRelease, Qt::Key_Right, Qt::NoModifier));
QApplication::processEvents();
setCursorPosition(cp);
}
geekowl
20th October 2017, 16:00
As a trick:
if(isReadOnly()){
setReadOnly(false);
setSelection(text().length(), text().length() + 1);
}
Powered by vBulletin® Version 4.2.5 Copyright © 2024 vBulletin Solutions Inc. All rights reserved.