Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. Disable changing of shape of cursor when it inside of QTextEdit
Forum Updated to NodeBB v4.3 + New Features

Disable changing of shape of cursor when it inside of QTextEdit

Scheduled Pinned Locked Moved Unsolved General and Desktop
28 Posts 3 Posters 3.8k Views 2 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • K Offline
    K Offline
    Kaznachei
    wrote on 28 Apr 2019, 09:10 last edited by
    #1

    I have MainWindow, custom GraphicsView and QGraphicsScene. In QGraphicsScene added QGraphicsRectItem. In QGraphicsRectItem added QTextEdit (I want have oportunity to rotate QTextEdit). I want to disable changing of shape of cursor when it inside of QTextEdit. How can i do it?

    1 Reply Last reply
    0
    • M Offline
      M Offline
      mrjj
      Lifetime Qt Champion
      wrote on 28 Apr 2019, 09:20 last edited by
      #2

      Hi
      You mean, you dont want it to be editable ?

      1 Reply Last reply
      0
      • K Offline
        K Offline
        Kaznachei
        wrote on 28 Apr 2019, 10:30 last edited by
        #3

        For example, i clicked on QPushButton then QTextEdit doesn`t react to mouse events ( i dont want to use setEnabled, because it changes color to gray). I clicked on QPushButton then QTextEdit starts to react to mouse events.

        M 1 Reply Last reply 28 Apr 2019, 10:50
        0
        • K Kaznachei
          28 Apr 2019, 10:30

          For example, i clicked on QPushButton then QTextEdit doesn`t react to mouse events ( i dont want to use setEnabled, because it changes color to gray). I clicked on QPushButton then QTextEdit starts to react to mouse events.

          M Offline
          M Offline
          mrjj
          Lifetime Qt Champion
          wrote on 28 Apr 2019, 10:50 last edited by
          #4

          @Kaznachei
          Hi
          Ok. try
          myTextEdit->setReadOnly(true);

          1 Reply Last reply
          1
          • K Offline
            K Offline
            Kaznachei
            wrote on 28 Apr 2019, 10:55 last edited by
            #5

            Yes, i did it already, but shape of cursor changes when My cursor in QTextEdit

            M 1 Reply Last reply 28 Apr 2019, 10:59
            0
            • K Kaznachei
              28 Apr 2019, 10:55

              Yes, i did it already, but shape of cursor changes when My cursor in QTextEdit

              M Offline
              M Offline
              mrjj
              Lifetime Qt Champion
              wrote on 28 Apr 2019, 10:59 last edited by mrjj
              #6

              @Kaznachei
              ah. now i get it,
              it changes when you hover the mouse over it and you dont want that.
              even with
              setTextInteractionFlags(Qt::NoTextInteraction);
              it still does that.

              I have not seen a setting for it.
              You should be able to install event filter on it and eat the EnterEvent
              which should stop it from changing. However,
              i have not tried it.

              1 Reply Last reply
              0
              • K Offline
                K Offline
                Kaznachei
                wrote on 28 Apr 2019, 11:08 last edited by
                #7

                What i should to override?

                M 1 Reply Last reply 28 Apr 2019, 11:09
                0
                • K Kaznachei
                  28 Apr 2019, 11:08

                  What i should to override?

                  M Offline
                  M Offline
                  mrjj
                  Lifetime Qt Champion
                  wrote on 28 Apr 2019, 11:09 last edited by mrjj
                  #8

                  @Kaznachei
                  Just saw something

                  docs 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

                  1 Reply Last reply
                  0
                  • M Offline
                    M Offline
                    mrjj
                    Lifetime Qt Champion
                    wrote on 28 Apr 2019, 11:11 last edited by
                    #9

                    Hi
                    Try
                    ui->textEdit->viewport()->setCursor(Qt::ArrowCursor);
                    works here :)

                    1 Reply Last reply
                    2
                    • K Offline
                      K Offline
                      Kaznachei
                      wrote on 28 Apr 2019, 11:19 last edited by
                      #10

                      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)

                      M 1 Reply Last reply 28 Apr 2019, 11:34
                      0
                      • K Kaznachei
                        28 Apr 2019, 11:19

                        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)

                        M Offline
                        M Offline
                        mrjj
                        Lifetime Qt Champion
                        wrote on 28 Apr 2019, 11:34 last edited by mrjj
                        #11

                        @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 ?

                        1 Reply Last reply
                        2
                        • K Offline
                          K Offline
                          Kaznachei
                          wrote on 28 Apr 2019, 12:08 last edited by
                          #12

                          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?

                          M 1 Reply Last reply 28 Apr 2019, 12:13
                          0
                          • K Kaznachei
                            28 Apr 2019, 12:08

                            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?

                            M Offline
                            M Offline
                            mrjj
                            Lifetime Qt Champion
                            wrote on 28 Apr 2019, 12:13 last edited by
                            #13

                            @Kaznachei
                            Hi, yes that should be fine.
                            Should not be heavy.

                            1 Reply Last reply
                            0
                            • K Offline
                              K Offline
                              Kaznachei
                              wrote on 28 Apr 2019, 12:20 last edited by Kaznachei
                              #14

                              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

                              M 1 Reply Last reply 28 Apr 2019, 12:38
                              0
                              • K Kaznachei
                                28 Apr 2019, 12:20

                                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

                                M Offline
                                M Offline
                                mrjj
                                Lifetime Qt Champion
                                wrote on 28 Apr 2019, 12:38 last edited by mrjj
                                #15

                                @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)

                                1 Reply Last reply
                                0
                                • K Offline
                                  K Offline
                                  Kaznachei
                                  wrote on 28 Apr 2019, 12:46 last edited by
                                  #16

                                  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);

                                  M 1 Reply Last reply 28 Apr 2019, 12:59
                                  0
                                  • K Kaznachei
                                    28 Apr 2019, 12:46

                                    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);

                                    M Offline
                                    M Offline
                                    mrjj
                                    Lifetime Qt Champion
                                    wrote on 28 Apr 2019, 12:59 last edited by
                                    #17

                                    @Kaznachei
                                    yes, looks right.
                                    "this" being GraphicsView with the eventFilter function, i assume.

                                    1 Reply Last reply
                                    0
                                    • K Offline
                                      K Offline
                                      Kaznachei
                                      wrote on 28 Apr 2019, 13:26 last edited by
                                      #18

                                      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 .

                                      M 1 Reply Last reply 28 Apr 2019, 13:31
                                      0
                                      • K Kaznachei
                                        28 Apr 2019, 13:26

                                        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 .

                                        M Offline
                                        M Offline
                                        mrjj
                                        Lifetime Qt Champion
                                        wrote on 28 Apr 2019, 13:31 last edited by
                                        #19

                                        @Kaznachei
                                        Hi
                                        The syntax is
                                        monitoredObj->installEventFilter(filterObj);

                                        monitoredObj = GraphicsItem

                                        filterObj = GraphicsView
                                        and this should have the
                                        :eventFilter(QObject* obj, QEvent *event)
                                        function.

                                        1 Reply Last reply
                                        0
                                        • K Offline
                                          K Offline
                                          Kaznachei
                                          wrote on 28 Apr 2019, 14:12 last edited by
                                          #20

                                          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.

                                          M 1 Reply Last reply 28 Apr 2019, 14:47
                                          0

                                          1/28

                                          28 Apr 2019, 09:10

                                          • Login

                                          • Login or register to search.
                                          1 out of 28
                                          • First post
                                            1/28
                                            Last post
                                          0
                                          • Categories
                                          • Recent
                                          • Tags
                                          • Popular
                                          • Users
                                          • Groups
                                          • Search
                                          • Get Qt Extensions
                                          • Unsolved