QListWidgetItem * QListWidget::itemAt ( const QPoint & p ) const Returns a pointer to the item at the coordinates p.
QListWidgetItem * QListWidget::itemAt ( int x, int y ) const This is an overloaded member function, provided for convenience. Returns a pointer to the item at the coordinates (x, y).
写好上面的代码,咦?还是不行?呵呵,我这里也不行。因为itemAt()中接受的坐标是ListWidget坐标系的。而通过QCursor::pos()获得坐标是全局坐标。需要映射到ListWidget上才可以,Qt Assist中是这样描述的。 QPoint QCursor::pos () [static] Returns the position of the cursor (hot spot) in global screen coordinates. You can call QWidget::mapFromGlobal() to translate it to widget coordinates. See also setPos(), QWidget::mapFromGlobal(), and QWidget::mapToGlobal().