PDA

View Full Version : 2 times click instead of double click (eg. renaming)



edb
12th January 2006, 13:51
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!

high_flyer
12th January 2006, 14:09
You can use the QWidget::mousePressEvent() and mesure the time between two of those...

edb
12th January 2006, 14:24
I will try that.

Do you have any idea what the usual time delay between the two clicks is when renaming an item?

yop
12th January 2006, 14:31
For sure it should be more than QApplication::doubleClickInterval ()

mcosta
12th January 2006, 14:34
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


void MyWidget::listItemClicked(QListWidgetItem* item)
{
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

edb
12th January 2006, 16:40
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


#ifndef mylistview_h
#define mylistview_h

#include <qlistview.h>
#include <iostream>

class MyListView : public QListView
{
Q_OBJECT

public:
MyListView(QWidget* parent = 0, const char* name = 0, WFlags f =0);

public slots:
void slotTestRename();
};

#endif




mylistview.cpp

#include "mylistview.h"

MyListView::MyListView(QWidget* parent, const char* name, WFlags f)
: QListView(parent, name, f)
{
connect(this, SIGNAL(itemRenamed(QListViewItem* , int)), this, SLOT(slotTestRename()));
}
void MyListView::slotTestRename()
{
std::cout << "RENAMED " << std::endl;
}



mainfile:


#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[])
{
QApplication a(argc,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();
}