Hi, closing this thread.
To sum up, my issue stems from a Qt layout limitation, for posterity's sake here's the solution that I ended up using to get around my problem:
I installed an eventFilter on my QLabel, filtering for QSinglePointEvent and checking wether the cursor was within the text, here's a small code example:
bool SubWidget::eventFilter(QObject * iObject, QEvent* iEvent){
if ((iObject == _label) && (iEvent->isSinglePointEvent())){ //if event is a mouse event on _label
QFontMetrics fm(_label->font());
int textWidth = fm.horizontalAdvance(_label->text()); // width of the text in pixels
int textHeight = fm.height(); // height of the text in pixels
int textX = 0;
int textY = 0;
// calculate the coordinates for the top-left pixel of the actual text, text position depends on alignment
if ((_label->alignment() & Qt::AlignLeft) == Qt::AlignLeft){
textX = _label->x();
}
else if ((_label->alignment() & Qt::AlignHCenter) == Qt::AlignHCenter){
textX = _label->x() + (_label->width() - textWidth)/2;
}
else if ((_label->alignment() & Qt::AlignRight) == Qt::AlignRight){
textX = _label->x() + _label->width() - textWidth;
}
if ((_label->alignment() & Qt::AlignTop) == Qt::AlignTop){
textY = _label->y();
}
else if ((_label->alignment() & Qt::AlignVCenter) == Qt::AlignVCenter){
textY = _label->y() + (_label->height() - textHeight)/2;
}
else if ((_label->alignment() & Qt::AlignBottom) == Qt::AlignBottom){
textY = _label->y() + _label->height() - textHeight;
}
QSinglePointEvent* pointEvent = static_cast<QSinglePointEvent*>(iEvent);
QPointF mousePos = pointEvent->position(); // Get mouse position relative to the label from the event
if ((textX <= mousePos.x() && mousePos.x() <= (textX + textWidth)) // if mouse is located within the text area
&& (textY <= mousePos.y() && mousePos.y() <= (textY + textHeight)))
{
//Do stuff here to further refine the event
//eg: hover event, mousepress event etc etc
return true;
}
else
{
return false;
}
}
return QWidget::eventFilter(iObject, iEvent);
}