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. Using the Scale function of QTransform
Forum Updated to NodeBB v4.3 + New Features

Using the Scale function of QTransform

Scheduled Pinned Locked Moved General and Desktop
2 Posts 2 Posters 3.2k 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.
  • X Offline
    X Offline
    xtraction
    wrote on last edited by
    #1

    Hello,

    I am looking to have some control of the scaling of a QImage I am displaying on a QGraphicsView. I implemented zooming functionality so you can zoom in and out of the image. For this I am using transforms in the following way:

    @
    //implemented in a zoom method in my QGraphicsClass

    QTransform transform;
    transform = m_transform.fromScale(scaleValue, 1.0);
    m_transform = transform;

    if( -- someCondition -- )
    {
        setTransform(m_transform, true);
        
       //Debugging code
        qDebug() << "VIEW" << width();
        qDebug() << "SCENE" << channelScene->width();
        qDebug() << "ITEM" << item->boundingRect().width();
    }
    else
        //don't zoom
    

    @

    In the above code right now I have if(true).. so the 'if' statement always executes so the image zooms in and out fine. What I want to restrict is that the image never gets smaller than the widget that contains it. So I need to find something to put in the condition of the if.
    I tried so far using m11() of the transform or using the boundingRect of the image but nothing seems to work.

    The debug code above which is the width of the view, the scene and the item NEVER change after applying the scaling transformation, so I can't find a way to restrict the zoom out to the point where it fits exactly in the container widget.
    My question is what does the setTransform in the Graphicsview scale? I thought it scales the view but then why when I do the debugging the width of the view never changes??
    Does anyone have some tips or ideas I can use to get control and never go under a particular value when zooming out?

    1 Reply Last reply
    0
    • Z Offline
      Z Offline
      ZapB
      wrote on last edited by
      #2

      That's because those measurements are in local coordinates. ie the item width never changes in its own coordinate system.

      I think you need to transform the item's bounding rect by the total transformation and see if the resulting rect is small than the view's viewport size.

      Nokia Certified Qt Specialist
      Interested in hearing about Qt related work

      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