Problem with QTextCursor selection
General and Desktop
5
Posts
2
Posters
4.0k
Views
1
Watching
-
Hi,
I'm have a situation where I need to customize the input to a QGraphicsTextItem. In particular, I need to select characters in response to an up-arrow key press. So I have created a custom QGraphicsTextItem and over-ridden the keyPressEvent,
@ class MyText : public QGraphicsTextItem
{
public:
MyText(const char* str) : QGraphicsTextItem(str)
{
}virtual void keyPressEvent(QKeyEvent* event) { QTextCursor cursor = textCursor(); if (event->key() == Qt::Key_Down) { cursor.movePosition(QTextCursor::Left,QTextCursor::KeepAnchor); } }
};@
Through the testing I've done, this is selecting text (e.g. if I called removeSelectedText() the text is correctly removed). The problem is that I need to have the visual indicator of the selection and I do not see it for some reason. Am I doing something wrong, or does the selection performed by QTextCursor not get displayed graphically?
-Josh