or even us QCoreApplication::sendEvent() to push an event through the normal event processing chain.
Using send event did allow me to do what I intended but nothing appears to be happening. Here's my class as of right now:
{
this->setMouseTracking(true);
layout->addWidget(label);
layout->addWidget(checkBox);
this->setLayout(layout);
}
if(label->contentsRect().contains(event->pos())){
QMouseEvent* newEvent
= new QMouseEvent(QEvent::MouseMove, checkBox
->mapFromGlobal
(checkBox
->pos
()), Qt
::NoButton, Qt
::NoButton, Qt
::NoModifier);
}else{
event->ignore();
}
}
CheckBoxTest::CheckBoxTest(QString text, QWidget *parent) :
QWidget(parent)
{
this->setMouseTracking(true);
label = new QLabel(text);
checkBox = new QCheckBox;
QHBoxLayout* layout = new QHBoxLayout;
layout->addWidget(label);
layout->addWidget(checkBox);
this->setLayout(layout);
}
void CheckBoxTest::mouseMoveEvent(QMouseEvent *event){
if(label->contentsRect().contains(event->pos())){
QMouseEvent* newEvent = new QMouseEvent(QEvent::MouseMove, checkBox->mapFromGlobal(checkBox->pos()), Qt::NoButton, Qt::NoButton, Qt::NoModifier);
QCoreApplication::sendEvent(checkBox, newEvent);
}else{
event->ignore();
}
}
To copy to clipboard, switch view to plain text mode
Mouse events are passed on to checkBox when not within the label. When within the label the newEvent is created with a mouse position of checkBox's position and I use sendEvent to send it to checkBox which should trigger a hover state whenever the mouse is in the contents of the label. Any idea why nothing seems to be happening?
Bookmarks