[Qt-interest] selection and cursor problems with focusless QLineEdit

Oliver Demetz forenbeitraege at oliverdemetz.de
Wed Jul 29 12:26:20 CEST 2009


Hi,

I'm developping a keyboard widget which shall popup if the user 
doubleclicks a QLineEdit. So far this works, I subclassed QLineEdit as 
follows:


class VirtualKeyboardLineEdit : public QLineEdit
{
public:
     VirtualKeyboardLineEdit( QWidget * parent = 0 )
     :QLineEdit(parent){};
     VirtualKeyboardLineEdit ( const QString & contents, QWidget * 
parent = 0 )
     :QLineEdit(contents, parent) {};
protected:
     void mouseDoubleClickEvent ( QMouseEvent * event )
     {
         VirtualKeyboard * vk = new VirtualKeyboard( this, Qt::Popup );
         vk->setAttribute(Qt::WA_DeleteOnClose);
         vk->show();
         QPoint pos = mapToGlobal(QPoint(0,0));
         pos.rx() += (this->frameGeometry().width() - 	
                         vk->frameGeometry().width())/2;
         pos.ry() -= vk->frameGeometry().height();
         vk->move(pos);
         selectAll();
     }
}

The cucial class VirtualKeyboard is just a subclass of QWidget, 
popularised with lots of QPushButtons, and each of these buttons creates 
and delivers a new QKeyEvent to the VirtualKeyboardLineEdit.

This works so far, but I have 2 problems:

A) When the virtual keyboard pops up (windowflags are Qt::Popup, so it 
looks and bahaves roughly like a context menu), the *cursor disappears* 
from the QLineEdit. It's is neither blinking nor painted at all. So the 
user does not know where his key press will have an effect.

B) See the last statement in the doubleclik event: selectAll().
The intention behind is that the current text can be deleted and 
overwritten immediately. But the click onto a button in the virtual 
keyboard removes the selecton (as if one clicked somewhere else). How 
can I keep the selection?

A third thing I do not really like:
It is not possible to open the keyboard and then click into the lineedit 
to change the cursor position. Any click into the lineedit closes the 
virtual keyboard.

I think a careful change of the window flags will make it possible to 
realise my intentions.

Buh, long text,
thanks for reading in advance.
Oliver



More information about the Qt-interest-old mailing list