[Qt-interest] doubleClick signal for QLineEdit

John McClurkin jwm at nei.nih.gov
Thu Jul 23 14:04:18 CEST 2009


M. Bashir Al-Noimi wrote:
> Donal O'Connor wrote:
>> I don't think there is a double click signal?
>>
>> This is an event.
> As I know in Qt's world "Event" terminology means "Signal" so you 
> surprised me when you've used "Event" terminology!
> For that could you tell me What's the different between "Event" and 
> "Signal" ?
> 
>>
>> You could inherit the QLineEdit and over ride/reimplement the 
>> ::mouseDoubleClickEvent event.
> I think this isn't suitable option because it's not compatible with 
> rapid developing.
>>
>> Or maybe install an event filter
>>
>>
> by using event filter I could catch mouse doubleClick by using this code:
> 
> bool MainWindow::eventFilter(QObject *obj, QEvent *event)
> {
>     if (obj == ui->lineEdit)
>     {
>         if (event->type() == QEvent::MouseButtonDblClick)
>         {
>             QKeyEvent *keyEvent = static_cast<QKeyEvent*>(event);
>             return true;
>         }
>         else
>             return false;
>     }
>     else
>         return QMainWindow::eventFilter(obj, event);
> }
> 
> 
> but this way is absolutely annoying because I've to write these line and 
> modify them everytime I add/modify/delete gui component. So I'm looking 
> for practical way just like "Go to slot..." in Qt Designer.
> 
> 

Well, the stock QLineEdit object doesn't emit any signals for mouse 
click events, so if you want one you will have subclass your own version 
of QLineEdit.

With a bit of clever design you won't have to modify your code every 
time you modify a gui element. Have your eventFilter emit a signal when 
it receives a MouseButtonDblClick event. Then, just connect the signal 
to a slot or don't. A signal that is not connected to any slots just 
harmlessly disappears.



More information about the Qt-interest-old mailing list