Unsolved Disable changing of shape of cursor when it inside of QTextEdit
-
@Kaznachei
Just saw somethingdocs says
The shape of the mouse cursor on a QTextEdit is Qt::IBeamCursor by default. It can be changed through the viewport()'s cursor property.
let me try it. 1 min
-
Hi
Try
ui->textEdit->viewport()->setCursor(Qt::ArrowCursor);
works here :) -
But if will be use it when i want to QTextEdit doesnt react to events(sometimes) it would be worse to use setCursor? (Because it reacts, and it spend time and resources)
-
@Kaznachei
setCursor is only called when you dont want the I beam cursor so should not be expensive.
An eventFilter would also cost CPU
so i think a ReadOnly TextEdit is as light as one with eventFilter.
However, why not try it out and see what you think ? -
It works, really thank you. Just i wanted to know which way is cheaper to solve my problem. As for me all that i saw was to too expensive. Is this way is ok? Just i wrote some SLOTS in my custom GraphicsRectItem
void lineChoosed()
{
text->viewport()->setCursor(Qt::ArrowCursor);
text->setReadOnly(true);
setAcceptHoverEvents(false);
setCursor(Qt::ArrowCursor);
}
void textChoosed()
{
text->viewport()->setCursor(Qt::IBeamCursor);
text->setReadOnly(false);
setAcceptHoverEvents(true);
}and in my custom GraphicsView when i create a new one GraphicsRectITem
connect(this, &GraphicsView::lineChoosed, item, &RectItem::lineChoosed);
connect(this, &GraphicsView::textChoosed, item, &RectItem::textChoosed);That means when i emit lineChoosed or textChoosed then are called my slots-functions as much as i have my custom GraphicsRectItem. Is it okay?
-
@Kaznachei
Hi, yes that should be fine.
Should not be heavy. -
Thank you a lot. May i know how can i realize it using eventFilter? I tried
text->setObjectName("text');and in GraphicsView::eventFilter(QObject* obj, QEvent *event)
{
if (obj->objectName() == "test") return false;
return QObject::eventFilter(obj, event);
}(obj->objectName() == "test") works but shape of cursor still changing
-
@Kaznachei
Hi
it's actually the viewport that does the most of it, so assign (installEventFilter) the eventFilter to
text->viewport() instead.
and check for viewports name instead. (or set it to test also) -
Like this ? I wrote it in GraphicsView
RectItem* item = new RectItem;
item->setObjectName("I");
item->setPos(event->pos() - QPoint(item->rect().width()/2, item->rect().height()/2));
item->text->viewport()->installEventFilter(this); -
@Kaznachei
yes, looks right.
"this" being GraphicsView with the eventFilter function, i assume. -
Oh, May i realize it? I want to my GraphicsView get events of my GraphicsItem. I want to my GraphicsView filters events of my GraphicsItem .
-
@Kaznachei
Hi
The syntax is
monitoredObj->installEventFilter(filterObj);monitoredObj = GraphicsItem
filterObj = GraphicsView
and this should have the
:eventFilter(QObject* obj, QEvent *event)
function. -
In GraphicsView
RectItem* item = new RectItem;
item->setObjectName("I");
item->setPos(event->pos() - QPoint(item->rect().width()/2, item->rect().height()/2));
item->installEventFilter(this);and
bool eventFilter(QObject *obj, QEvent *event)
{
if (obj->objectName() == "I")
qDebug() << "ok"
return QGraphicsView::eventFilter(obj, event);
}qDebug() doesn`t write.
-
@Kaznachei
Hi
try withbool eventFilter(QObject *obj, QEvent *event) { qDebug() << obj->objectName(); if (obj->objectName() == "I") qDebug() << "ok" return QGraphicsView::eventFilter(obj, event); }
and see what is going on
-
qDebug write only this
""
""
""
""
""
""
""
""
""
""
""
""
""
""
""
""
""
""
""
""
""
""
""
""
"" -
@Kaznachei
Hmm. odd.
Try
qDebug() << obj->metaObject()->className()
and see what type it is.Else use the debugger to see what obj is.
-
only
QScrollBar
QScrollBar
QScrollBar
QScrollBar
QScrollBar
QScrollBar -
Hi
Maybe eventFilters do not work on QGraphicsItems
I have never tested it but since they are not qobjects, i think its a no go. -
Yes. I read that QGraphicsObject has eventFilter, but not QGraphicsItem. Thank you a lot for ur helping.
-
@Kaznachei
yes QGraphicsObject also inherits from QObject so that makes good sense it can use event filters too.
You are most welcome.