Hi !

I Have a subclassed QScrollArea with a grid layout and it is dynamically filled with lots of thumbnails.
Each thumbnail image is placed into a QFrame which is then added into the grid layout
.. When they are all added I call adjustSize() and show the scrollarea.

I have reimplemented the scroll area's mousePressEvent(QMouseEvent *e) and to query
whether a thumbnail is being clicked my code is like this:

Qt Code:
  1. for (int i = 0; i < m_grdLayout->count(); i++)
  2. {
  3. QLayoutItem *layoutItem = m_grdLayout->itemAt(i);
  4. if (layoutItem->geometry().contains(e->pos()))
  5. {
  6. return layoutItem->widget();
  7. }
  8. }
To copy to clipboard, switch view to plain text mode 

It didn't work and I investigated it ... it seemed that the y coordinate e->pos() was
returning were always the same .. regardless of the size of the scroll area or where I
clicked within it. (up the top or down the bottom)

It was like the postion was relative to the boundary of the containing widget .. not the
scroll area.

I tried using every mapTo and mapFrom I could think of to transform pos of but I could
never get the position in the mouse event to be relative to the place in the scroll area it
was supposed to be.

so I changed my code to :
Qt Code:
  1. for (int i = 0; i < m_grdLayout->count(); i++)
  2. {
  3. QLayoutItem *layoutItem = m_grdLayout->itemAt(i);
  4. QWidget * w = layoutItem->widget();
  5. if (w->underMouse())
  6. return w;
  7. }
To copy to clipboard, switch view to plain text mode 
which works properly.

But why didn't my first try work ? What was I doing wrong ?

thanks for any pointers

barnaby.