There must be a way to check the contents of a stack of counters: what counters are in the stack and in what order.
The simplest way to do this is to display a popup window when the cursor is over the top (or any) counter of a stack. The cursor must remain stationary over the counter for a certain time to avoid unwanted popups.
To achieve this a timer is used (QTimer). The timer is initiated in the constructor and a timeout event connected to a handler (hooverAction()) that creates the popup window. Mouse tracking must be set to true.
Counter::QtCounter::QtCounter(Counter *owner) : QLabel(owner->parentFrame)
{
this->setAttribute(Qt::WA_DeleteOnClose);
this->setContextMenuPolicy(Qt::CustomContextMenu);
this->owner = owner;
this->timer = new QTimer(this);
this->timer->setSingleShot(true);
connect(timer, &QTimer::timeout, this, [=]()->void{ hooverAction(); });
this->setMouseTracking(true);
}
The timeout is set to 0,7 seconds, i.e. the time the cursor must be stationary. Any movement of the cursor resets the timer.
void Counter::QtCounter::mouseMoveEvent (QMouseEvent * e)
{
if (this->owner->parentFrame->name == "Map")
{
Counter::hooverView->setVisible(false);
popupPoint = e->position().toPoint();
timer->start(700);
}
}
When the cursor leaves the counter the timer is stopped. The popup window (if it was displayed) disappears (is made invisible).
void Counter::QtCounter::leaveEvent (QEvent *e)
{
if (this->owner->parentFrame->name == "Map")
{
Counter::hooverView->setVisible(false);
timer->stop();
}
}
Besides displaying the stack it is useful to display the portion of the map beneath the stack. This portion is of course hidden but it may be useful to be remained of what it is without having to move the stack.
The way counters and stacks are display had to be rewritten. The generation of stacks and the rendering of them is now done in parent frame of the counters (the CentralFrame class). The Counter::QtCounter class no longer has an overridden paintEvent handler. It is not needed.
For stacks with no offset, the stack size is now written in the upper right corner. The stack size marker is no longer painted on a counter but is painted on a separate frame above all the counters (Counter::Overlay class). The marker is now static with respect to the stack, i.e. always displayed in the same place relative to the counters.
It is useful to be able to paint on top of all counters. Likewise, it can be useful to paint beneath all counters. An example of painting on top: to draw a circle around a particular stack to draw attention to it. An example of painting below: to draw arrows and sketch paths of attack in a game. There is no limit to the number of paint surfaces above and below the map counters/cards for whatever purpose that may serve.
Code may be found [link to old code deleted].
Two no-offset stacks with stack size in upper right corner:

Hoovering over upper stack:

Hoovering over lower stack:

The test map is small so the maximum number of counters displayed per row is 3.
int StackFrame::maxColumns = 3;
After 3 counters a new row is made. At 10 counters per stack the map can no longer display the whole popup window (it is clipped by the lower edge). For real maps and a realistic stack size this limitation is not present.