0
votes

I have a widget on top of my mainwindow, more like and Advertisement Banner. It is preventing the user from using some functionalities behind it so I set it to

setAttribute( Qt::WA_TransparentForMouseEvents );

But that specific ad banner has 2 buttons, and if it set as 'transparent', they can't be used obvoiusly. My question is that, how can I still use the button functionalities inside the banner of it set to transparent for mouse events?

It looks like this:

enter image description here

1

1 Answers

1
votes

Made a solution using the Mouse Events of the said Banner Widget:

void advertisement::mouseMoveEvent(QMouseEvent *event)
{
    qDebug()<< event->button();
    if (isRightBtn)
    {
        this->setAttribute(Qt::WA_TransparentForMouseEvents);
        main->_IsCamRotate = true;
        main->triggerMouseMove(event);
    }
}

void advertisement::mousePressEvent(QMouseEvent *event)
{
    qDebug()<< event->button();
    switch(event->button())
    {
    case Qt::MouseButton::RightButton:
        isRightBtn = true;
        break;
    }
}


void advertisement::mouseReleaseEvent(QMouseEvent *event)
{
    if (!this->rect().contains(event->pos()) && event->button() == Qt::MouseButton::RightButton)
    {
        main->triggerMouseRelease(event);
        isRightBtn = false;

        this->setAttribute(Qt::WA_TransparentForMouseEvents, false);
    }
}