I have tried the installeventFilter as well, I am now pasting the code as I think it might be the problem with my code.
Here is my class:
SelectableItem_C
::SelectableItem_C(QWidget* parent
) {
_label_textedit->setFont(font);
_label_textedit->setAlignment(Qt::AlignCenter);
_label_textedit->setPaletteBackgroundColor(dark_background);
_label_textedit->setAutoFillBackground(true);
_label_textedit
->setFrameShape
(QFrame::NoFrame);
_label_textedit
->setWordWrapMode
(QTextOption::WrapAtWordBoundaryOrAnywhere);
_label_textedit->setVerticalScrollBarPolicy(Qt::ScrollBarAlwaysOff);
_label_textedit->setHorizontalScrollBarPolicy(Qt::ScrollBarAlwaysOff);
_label_textedit->setTextInteractionFlags(Qt::NoTextInteraction);
QSizePolicy sizePolicy
(static_cast<QSizePolicy
::Policy>
(5), static_cast<QSizePolicy
::Policy>
(5));
sizePolicy.setHorizontalStretch(0);
sizePolicy.setVerticalStretch(0);
sizePolicy.setHeightForWidth(_label_textedit->sizePolicy().hasHeightForWidth());
_label_textedit->setSizePolicy(sizePolicy);
_label_textedit->viewport()->setCursor(Qt::ArrowCursor);
_label_textedit->installEventFilter(this);
_label_textedit->viewport()->setMouseTracking(true);
}
SelectableItem_C::SelectableItem_C(QWidget* parent)
{
_label_textedit = new QTextEdit(this);
_label_textedit->setFont(font);
_label_textedit->setAlignment(Qt::AlignCenter);
_label_textedit->setPaletteBackgroundColor(dark_background);
_label_textedit->setAutoFillBackground(true);
_label_textedit->setFrameShape(QFrame::NoFrame);
_label_textedit->setWordWrapMode(QTextOption::WrapAtWordBoundaryOrAnywhere);
_label_textedit->setVerticalScrollBarPolicy(Qt::ScrollBarAlwaysOff);
_label_textedit->setHorizontalScrollBarPolicy(Qt::ScrollBarAlwaysOff);
_label_textedit->setTextInteractionFlags(Qt::NoTextInteraction);
QSizePolicy sizePolicy(static_cast<QSizePolicy::Policy>(5), static_cast<QSizePolicy::Policy>(5));
sizePolicy.setHorizontalStretch(0);
sizePolicy.setVerticalStretch(0);
sizePolicy.setHeightForWidth(_label_textedit->sizePolicy().hasHeightForWidth());
_label_textedit->setSizePolicy(sizePolicy);
_label_textedit->viewport()->setCursor(Qt::ArrowCursor);
_label_textedit->installEventFilter(this);
_label_textedit->viewport()->setMouseTracking(true);
}
To copy to clipboard, switch view to plain text mode
and here is the event filter function in this class
{
//printf("got in\n");
if ( obj == _label_textedit )
{
if ( ev
->type
() == QEvent::MouseButtonPress ) {
emit MousePressed_Signal(this);
return TRUE;
}
}
else
{
//printf("af: %d,%d\n",e->x(),e->y());
// pass the event on to the parent class
return QWidget::eventFilter( obj, ev
);
}
return TRUE;
}
bool SelectableItem_C::eventFilter( QObject *obj, QEvent *ev )
{
//printf("got in\n");
if ( obj == _label_textedit )
{
if ( ev->type() == QEvent::MouseButtonPress )
{
emit MousePressed_Signal(this);
return TRUE;
}
}
else
{
//printf("af: %d,%d\n",e->x(),e->y());
// pass the event on to the parent class
return QWidget::eventFilter( obj, ev );
}
return TRUE;
}
To copy to clipboard, switch view to plain text mode
I have defined a "MousePressed_Signal" which is doing the desired work.
I could not even come in to the "If condition" with my debugging.
One more thing is that I have overridden the functions "mousePressEvent" and "mouseDoubleClickEvent" for my class. I can see that control goes to the function "mouseDoubleClickEvent" when I double click on the QTextEdit control, but not when I just do a single click on the same QTextEdit ?
Bookmarks