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.5k 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 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?

    mrjjM 1 Reply Last reply
    0
    • K Kaznachei

      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?

      mrjjM Offline
      mrjjM Offline
      mrjj
      Lifetime Qt Champion
      wrote on 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 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

        mrjjM 1 Reply Last reply
        0
        • K Kaznachei

          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

          mrjjM Offline
          mrjjM Offline
          mrjj
          Lifetime Qt Champion
          wrote on 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 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);

            mrjjM 1 Reply Last reply
            0
            • K Kaznachei

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

              mrjjM Offline
              mrjjM Offline
              mrjj
              Lifetime Qt Champion
              wrote on 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 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 .

                mrjjM 1 Reply Last reply
                0
                • K Kaznachei

                  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 .

                  mrjjM Offline
                  mrjjM Offline
                  mrjj
                  Lifetime Qt Champion
                  wrote on 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 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.

                    mrjjM 1 Reply Last reply
                    0
                    • K Kaznachei

                      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.

                      mrjjM Offline
                      mrjjM Offline
                      mrjj
                      Lifetime Qt Champion
                      wrote on last edited by
                      #21

                      @Kaznachei
                      Hi
                      try with

                      bool 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

                      1 Reply Last reply
                      0
                      • K Offline
                        K Offline
                        Kaznachei
                        wrote on last edited by
                        #22

                        qDebug write only this

                        ""
                        ""
                        ""
                        ""
                        ""
                        ""
                        ""
                        ""
                        ""
                        ""
                        ""
                        ""
                        ""
                        ""
                        ""
                        ""
                        ""
                        ""
                        ""
                        ""
                        ""
                        ""
                        ""
                        ""
                        ""

                        mrjjM 1 Reply Last reply
                        0
                        • K Kaznachei

                          qDebug write only this

                          ""
                          ""
                          ""
                          ""
                          ""
                          ""
                          ""
                          ""
                          ""
                          ""
                          ""
                          ""
                          ""
                          ""
                          ""
                          ""
                          ""
                          ""
                          ""
                          ""
                          ""
                          ""
                          ""
                          ""
                          ""

                          mrjjM Offline
                          mrjjM Offline
                          mrjj
                          Lifetime Qt Champion
                          wrote on last edited by
                          #23

                          @Kaznachei
                          Hmm. odd.
                          Try
                          qDebug() << obj->metaObject()->className()
                          and see what type it is.

                          Else use the debugger to see what obj is.

                          1 Reply Last reply
                          0
                          • K Offline
                            K Offline
                            Kaznachei
                            wrote on last edited by
                            #24

                            only
                            QScrollBar
                            QScrollBar
                            QScrollBar
                            QScrollBar
                            QScrollBar
                            QScrollBar

                            1 Reply Last reply
                            0
                            • mrjjM Offline
                              mrjjM Offline
                              mrjj
                              Lifetime Qt Champion
                              wrote on last edited by
                              #25

                              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.

                              1 Reply Last reply
                              0
                              • K Offline
                                K Offline
                                Kaznachei
                                wrote on last edited by
                                #26

                                Yes. I read that QGraphicsObject has eventFilter, but not QGraphicsItem. Thank you a lot for ur helping.

                                mrjjM 1 Reply Last reply
                                0
                                • K Kaznachei

                                  Yes. I read that QGraphicsObject has eventFilter, but not QGraphicsItem. Thank you a lot for ur helping.

                                  mrjjM Offline
                                  mrjjM Offline
                                  mrjj
                                  Lifetime Qt Champion
                                  wrote on last edited by
                                  #27

                                  @Kaznachei
                                  yes QGraphicsObject also inherits from QObject so that makes good sense it can use event filters too.
                                  You are most welcome.

                                  1 Reply Last reply
                                  0
                                  • SGaistS Offline
                                    SGaistS Offline
                                    SGaist
                                    Lifetime Qt Champion
                                    wrote on last edited by
                                    #28

                                    Hi,

                                    You might be interested by the installSceneEventFilter method

                                    Interested in AI ? www.idiap.ch
                                    Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

                                    1 Reply Last reply
                                    1

                                    • Login

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