Re:press on hold does not work
Clive Levinson <[email protected]> Tue, 24 Sep 2002 21:09:27 -0700
| Newsgroups | gmane.comp.handhelds.zaurus.devel |
|---|---|
| Message-ID | <[email protected]> |
>I would like to use the stylus press on hold feature to emulate a
right-button event.
>I use the QPEApplication::setStylusOperation on the App, on the view, on the
>widget... no success. Can someone give a hint how to do it right ?
>Thank you
>Eggert Ehmke
Hi Eggert,
I also tried the QPEApplication::setStylusOperation, but I could not get it to
work. I eventually used a timer to get it working, see the snippet of code
below. My example uses a listview, but it should work with most QT windows.
class CmyListView : public QListView
{
Q_OBJECT
public:
CmyListView (QWidget *parent=0);
~CmyListView();
private:
QTimer *m_dblClickTimer;
QListViewItem *m_clickedItem;
int m_clickedCol;
public slots:
void slotLeftButtonClicked(QListViewItem *item,const QPoint &point,int col);
void slotLeftButtonPressed(QListViewItem *item,const QPoint &point,int col);
void slotDblClickTimedOut(void);
};
CmyListView::~CmyListView ()
{
//I can never remember with QT, what I am supposed to delete
//and what QT deletes. It would have been so much simpler
//if they had of left all deletion to the application developer.
if(m_dblClickTimer!=NULL)
delete m_dblClickTimer;
}
CmyListView::CmyListView(QWidget *parent)
:QListView(parent)
{
m_dblClickTimer=new QTimer(this); //create the timer
m_clickedItem=NULL; //the listview item that
is pressed and held
m_clickedCol=-1; //the selected
column in the listview.
connect(this,SIGNAL(pressed(QListViewItem *,const QPoint &,int)),
this,SLOT(slotLeftButtonPressed(QListViewItem *,const QPoint
&,int)));
connect(this,SIGNAL(clicked(QListViewItem *,const QPoint &,int)),
this,SLOT(slotLeftButtonClicked(QListViewItem *,const
QPoint &,int)));
connect(m_dblClickTimer,SIGNAL(timeout()),
this,SLOT(slotDblClickTimedOut()));
}
void CmyListView::slotLeftButtonPressed(QListViewItem *item, const QPoint
&, int col)
{
m_clickedItem=item;
m_clickedCol=col;
m_dblClickTimer->start(750); //750 mSeconds this timeout seems to work well
}
void CmyListView::slotLeftButtonClicked(QListViewItem *,const QPoint &,int)
{
m_clickedItem=NULL;
m_clickedCol=-1;
m_dblClickTimer->stop();
}
void CmyListView::slotDblClickTimedOut(void)
{
m_dblClickTimer->stop();
//This is where you get after the press and hold.
//because I used a list view, m_clickedItem should now contain
//a pointer to the listviewitem that was pressed and held.
//m_clickedCol should contain the column number
}
I hope that helps,
Regards,
Clive
================================
Bundu Technology Ltd.
http://www.bundu.com
Custom hardware & software design and development.
Windows, Palm, Linux & Embedded microcontrollers.
================================
-------------------------------------------------------
This sf.net email is sponsored by:ThinkGeek
Welcome to geek heaven.
http://thinkgeek.com/sf