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. In rubber band rectangle zoom in, rectangle is not visible.
Qt 6.11 is out! See what's new in the release blog

In rubber band rectangle zoom in, rectangle is not visible.

Scheduled Pinned Locked Moved Unsolved General and Desktop
8 Posts 2 Posters 863 Views 1 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.
  • T Offline
    T Offline
    tushu
    wrote on last edited by tushu
    #1

    I am using rubber band rectangle zoom in.
    There are 2 cases for rubber band rectangle creation according to point selection ( rectangles start point ( top left ) and end point ( right bottom)

    1. Starting point of rectangle is on the blank space
    2. Starting point is on QGraphicsItem.

    Zoom.PNG

    Above diagram shows, 2nd case. Starting point (point A) is inside QGraphicsItem.
    And in this case I am not able to see rubber band rectangle. But it gives proper output. ( it zoom in that particular area)

    Here is my code:

    bool myViewer::eventFilter(QObject* watched, QEvent* event)
    {
        bool filterEvent = false;
        switch (event->type()) {
        case QEvent::MouseButtonPress: {
                QMouseEvent* mouseEvent = static_cast<QMouseEvent*>(event);
                _rubberBandOrigin = mouseEvent->pos();
                _rubberBandActive = true;
    break;
    }
    
    case QEvent::MouseButtonRelease: {
            if (_rubberBandActive) {
                QMouseEvent* mouseEvent = static_cast<QMouseEvent*>(event);
                _rubberBandEnd = mouseEvent->pos();
                QGraphicsView* view = static_cast<QGraphicsView*>(watched->parent());
                QRectF zoomRectInScene = QRectF(view->mapToScene(_rubberBandOrigin), view->mapToScene(_rubberBandEnd));
                    view->fitInView(zoomRectInScene, Qt::KeepAspectRatio);
                _rubberBandActive = false;
            }
            break;
    

    Issue :
    I want to see rubber band rectangle in above case also.
    P.S. In above case, I get correct output ( i.e. area gets zoomed in ) but not able to see rubber band rectangle.

    If I removed yellow color of rectangle, still I can not see rubber band rectangle.

    SGaistS 1 Reply Last reply
    0
    • T tushu

      I am using rubber band rectangle zoom in.
      There are 2 cases for rubber band rectangle creation according to point selection ( rectangles start point ( top left ) and end point ( right bottom)

      1. Starting point of rectangle is on the blank space
      2. Starting point is on QGraphicsItem.

      Zoom.PNG

      Above diagram shows, 2nd case. Starting point (point A) is inside QGraphicsItem.
      And in this case I am not able to see rubber band rectangle. But it gives proper output. ( it zoom in that particular area)

      Here is my code:

      bool myViewer::eventFilter(QObject* watched, QEvent* event)
      {
          bool filterEvent = false;
          switch (event->type()) {
          case QEvent::MouseButtonPress: {
                  QMouseEvent* mouseEvent = static_cast<QMouseEvent*>(event);
                  _rubberBandOrigin = mouseEvent->pos();
                  _rubberBandActive = true;
      break;
      }
      
      case QEvent::MouseButtonRelease: {
              if (_rubberBandActive) {
                  QMouseEvent* mouseEvent = static_cast<QMouseEvent*>(event);
                  _rubberBandEnd = mouseEvent->pos();
                  QGraphicsView* view = static_cast<QGraphicsView*>(watched->parent());
                  QRectF zoomRectInScene = QRectF(view->mapToScene(_rubberBandOrigin), view->mapToScene(_rubberBandEnd));
                      view->fitInView(zoomRectInScene, Qt::KeepAspectRatio);
                  _rubberBandActive = false;
              }
              break;
      

      Issue :
      I want to see rubber band rectangle in above case also.
      P.S. In above case, I get correct output ( i.e. area gets zoomed in ) but not able to see rubber band rectangle.

      If I removed yellow color of rectangle, still I can not see rubber band rectangle.

      SGaistS Offline
      SGaistS Offline
      SGaist
      Lifetime Qt Champion
      wrote on last edited by
      #2

      Hi,

      You should also add the code that handles the rubber band itself. You might be using the wrong coordinates to position it.

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

      T 1 Reply Last reply
      0
      • SGaistS SGaist

        Hi,

        You should also add the code that handles the rubber band itself. You might be using the wrong coordinates to position it.

        T Offline
        T Offline
        tushu
        wrote on last edited by
        #3

        @SGaist After searching on internet, I found reason for this.
        When I try to create rubber band rectangle on blank space, it gets created on scene, so paint() gets called and we can see rubber band rectangle.

        But when we try to create rubber band rectangle on QGraphicsRectItem, it is not creating on scene but creating on rectangle. So paint does not get called.

        So I tried 1 solution :
        When I will create top left corner of rectangle, I am getting that point and checking under that point is there any object.
        If it has any object under it, then I am changing it's opacity by setOpacity(0.0) and when I release mouse ( i.e. creating bottom right points of rectangle) I am again setting it's opacity to normal.
        And in this , I can see rubber band rectangle has been created.
        But this way is not good, because for some time, due to low opacity, rectangle's border gets disappear, which I dont want.

        Is there any alternative ?

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

          Can you show exactly how you manage your rubber band ?
          Are you other items movable ?

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

          T 1 Reply Last reply
          0
          • SGaistS SGaist

            Can you show exactly how you manage your rubber band ?
            Are you other items movable ?

            T Offline
            T Offline
            tushu
            wrote on last edited by
            #5

            @SGaist This is the rubber band code. I have given full code.
            I dont have any items movable.
            I just changed opacity of rectangle and I could see my rubber band rectangle.
            But I dont want this way.
            Is there any better way ?

            SGaistS 1 Reply Last reply
            0
            • T tushu

              @SGaist This is the rubber band code. I have given full code.
              I dont have any items movable.
              I just changed opacity of rectangle and I could see my rubber band rectangle.
              But I dont want this way.
              Is there any better way ?

              SGaistS Offline
              SGaistS Offline
              SGaist
              Lifetime Qt Champion
              wrote on last edited by
              #6

              Sorry but I did not see anywhere in your code where you actually create, update or do any operation on a QRubberBand object.

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

              T 1 Reply Last reply
              0
              • SGaistS SGaist

                Sorry but I did not see anywhere in your code where you actually create, update or do any operation on a QRubberBand object.

                T Offline
                T Offline
                tushu
                wrote on last edited by tushu
                #7

                @SGaist I have given you all the code related to rubber band rectangle.
                rubberBandOrigin ( from event mouse button pressed ) and rubberBandEnd ( from event mouse button released) are rectangles top left and bottom right points.

                And

                QRectF zoomRectInScene = QRectF(view->mapToScene(_rubberBandOrigin), view->mapToScene(_rubberBandEnd));
                                view->fitInView(zoomRectInScene, Qt::KeepAspectRatio);
                

                draws rubber band rectangle.

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

                  Ok, is see the issue: I took you use the QRubberBand class for your purpose.

                  Based on what you want to do, it seems it would be simpler. The rubber band being independent of the view will also not be dependent of if for its rendering.

                  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
                  0

                  • Login

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