2 times click instead of double click (eg. renaming)
Hi all,
I ame looking for a way to check whether a user pressed the left mouse button twice within a minimal time periode, but which is different from the double click signal. I want to use this for renaming a qlistview item as this is normally done. At the moment I use the double click signal and the renaming works fine, but I would like to connect the renaming to the "2 times click" as this is normally done for renaming. How can I do this?
Thanx!
Re: 2 times click instead of double click (eg. renaming)
You can use the QWidget::mousePressEvent() and mesure the time between two of those...
Re: 2 times click instead of double click (eg. renaming)
I will try that.
Do you have any idea what the usual time delay between the two clicks is when renaming an item?
Re: 2 times click instead of double click (eg. renaming)
For sure it should be more than QApplication::doubleClickInterval ()
Re: 2 times click instead of double click (eg. renaming)
Quote:
Originally Posted by edb
Hi all,
I ame looking for a way to check whether a user pressed the left mouse button twice within a minimal time periode, but which is different from the double click signal. I want to use this for renaming a qlistview item as this is normally done. At the moment I use the double click signal and the renaming works fine, but I would like to connect the renaming to the "2 times click" as this is normally done for renaming. How can I do this?
Thanx!
I have a solution!
You can connect QListWidget::itemClicked(QListWidgetItem* item) signal to a slot (i.e. MyWidget::listItemClicked(QListWidgetItem* item)) like
Code:
{
if(listWidget->itemIsSelected(item))
{
// Clicked item is previously selected
// Edit item
}
else
{
// Select the item
listWidget->setCurrentItem(item);
}
}
In this way user can edit list item text selecting item and then clicking on it (like Windows icon text).
Bye
Re: 2 times click instead of double click (eg. renaming)
Something very strange is happening... During my testing for the sollutions given above I came accross the following:
I have written some testcode as shown below . If you run this, you can see that renaming seems to be already implemented in QT and all you have to do is catch the itemRenamed.... I have never seen this before, but it seems to work fine! The connection below makes sure you can do whathever you want when an item is renamed...
mylistview.h
Code:
#ifndef mylistview_h
#define mylistview_h
#include <qlistview.h>
#include <iostream>
{
Q_OBJECT
public:
MyListView
(QWidget* parent
= 0,
const char* name
= 0, WFlags f
=0);
public slots:
void slotTestRename();
};
#endif
mylistview.cpp
Code:
#include "mylistview.h"
MyListView
::MyListView(QWidget* parent,
const char* name, WFlags f
) {
connect(this, SIGNAL(itemRenamed(QListViewItem* , int)), this, SLOT(slotTestRename()));
}
void MyListView::slotTestRename()
{
std::cout << "RENAMED " << std::endl;
}
mainfile:
Code:
#ifdef HAVE_CONFIG_H
#include <config.h>
#endif
#include <stdio.h>
#include <stdlib.h>
#include <qapplication.h>
#include <mylistview.h>
int main(int argc, char *argv[])
{
MyListView* listview = new MyListView();
listview->addColumn("testcolumn");
a.setMainWidget(listview);
QListViewItem* item = new QListViewItem(listview);
item->setText(0, "trial");
item->setRenameEnabled(0, true);
listview->show();
//myMainWindow->showMaximized();
return a.exec();
}