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. How to create of Viewport size on Rectangle selection

How to create of Viewport size on Rectangle selection

Scheduled Pinned Locked Moved Unsolved General and Desktop
5 Posts 3 Posters 1.0k 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.
  • J Offline
    J Offline
    Jaisan
    wrote on last edited by
    #1

    How to change the viewport size in the view on Rubber band selection of the items.
    only view should be zoomed with out change in any items size or positions.

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

      Hi and welcome to devnet,

      What view are you talking about ?

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

      J 1 Reply Last reply
      0
      • SGaistS SGaist

        Hi and welcome to devnet,

        What view are you talking about ?

        J Offline
        J Offline
        Jaisan
        wrote on last edited by
        #3

        here i am going to use ViewPort in QGraphicsView.

        all items which intersects the rubberband drag should be drawn inside the viewport of the viewscreen.

        raven-worxR 1 Reply Last reply
        0
        • J Jaisan

          here i am going to use ViewPort in QGraphicsView.

          all items which intersects the rubberband drag should be drawn inside the viewport of the viewscreen.

          raven-worxR Offline
          raven-worxR Offline
          raven-worx
          Moderators
          wrote on last edited by raven-worx
          #4

          @Jaisan
          Untested, so forgive any possible compile issues, but it should give you an idea:

          class MyGraphicsView : public QGraphicsVIew
          {
          public:
              MyGraphicsView( QWidget* parent = Q_NULLPTR )
                  : QGraphicsView(parent)
              {
                  mRubberBand = new QRubberBand( QRubberBand::Rectangle, this->viewport() );
                  mRubberBand->hide();
              }
              
          protected:
              QRubberBand* mRubberBand;
              QPoint mOrigin;
          
              virtual bool viewportEvent(QEvent * event)
              {
                  switch( event->type() )
                  {
                      case QEvent::MouseButtonPress:
                      {
                          QMouseEvent* me = static_cast<QMouseEvent*>( event );
                          if( me->button() == Qt::LeftButton )
                          {
                              mOrigin = me->pos();
                              mRubberBand->setGeometry(QRect(origin, QSize()));
                              mRubberBand->show();
                          }
                      }
                      break;
                      case QEvent::MouseMove:
                      {
                          if( mRubberBand.isVisible() )
                          {
                              QMouseEvent* me = static_cast<QMouseEvent*>( event );
                              mRubberBand->setGeometry(QRect(mOrigin, me->pos()).normalized());
                          }
                      }
                      break;
                      case QEvent::MouseButtonRelease:
                      {
                          if( mRubberBand.isVisible() )
                          {
                              mRubberBand->hide();
                          
                              QList<QGraphicsItem*> items = this->items( mRubberBand->geometry() );
                          
                              QRectF itemsRect;
                              foreach( QGraphicsItem* item, items )
                                   itemsRect |= item->screneRect();
                              if( itemsRect.isValid() )
                                   this->fitInView( itemsRect );
                          }
                      }
                      break;
                  }
                  
                  return QGraphicsView::viewportEvent(event);
              }
          };
          
          

          --- SUPPORT REQUESTS VIA CHAT WILL BE IGNORED ---
          If you have a question please use the forum so others can benefit from the solution in the future

          1 Reply Last reply
          2
          • J Offline
            J Offline
            Jaisan
            wrote on last edited by
            #5

            thanks its works fine

            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