Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8300717
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 8, 20262026-06-08T16:39:39+00:00 2026-06-08T16:39:39+00:00

I have a need to integrate a zoom slider for a QGraphicsView in Qt

  • 0

I have a need to integrate a zoom slider for a QGraphicsView in Qt 4.x, I have a working implementation that goes something like this:

connect(slider, SIGNAL(valueChanged(int)), customGraphicsView, SLOT(setZoomLevel(int));

In the slot for setZoomLevel I have the following

void CustomView::setZoomLevel(int level)
{
    if(zoomLevel - level < -1){
        setZoomLevel(level - 1);
    }else if(level - zoomLevel < -1){
        setZoomLevel(level + 1);
    }
    if(level < zoomLevel){
        scale(1 - (scaleFactor * (zoomLevel - level)), 1 - (scaleFactor * (zoomLevel - level)));
    }else if (level > zoomLevel){
        scale(1 + (scaleFactor * (level -  zoomLevel)), 1 + (scaleFactor * (level -  zoomLevel)));
    }

    zoomLevel = level;
}

So my issue is stemming from mating a slider which has a value of n to m to represent a zoom level to the scale() function of QGraphicsView, which takes two floating point values to multiply the scene by to get a new size.

So the problem I’m having is, if you take 1 * .9 * 1.1 you do not still get 1 but instead .99, its off slightly because it isn’t a correct formula. So my max zoom gets smaller and smaller over time.

The recursive calls are because the slider would sometimes skip values on fast slides, which increased the “error”, so I smoothed it out to bandage it a little.

Is there a correct way of handling zooms?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-08T16:39:42+00:00Added an answer on June 8, 2026 at 4:39 pm

    This took me a while to figure out too. The problem is that QGraphicsView::scale() combines the scale level with the current scale level. Instead try:

    setTransform(QTransform::fromScale(sx, sy));
    

    Notice in the documentation that there’s an optional second parameter of combine = false. This is good because you don’t want to combine the transforms.

    If you have other transformations on your QGraphicsView besides scaling, the above suggestion will discard them. In that case you would just use QGraphicsView::transform() to get the current transform, which you can alter however you like, and then use QGraphicsView::setTransform() to set it again.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have found this project on Codeplex. http://www.codeplex.com/ProjNET I need to integrate this code
I have an application we bought that I need to integrate, and it uses
I have a Java application that I need to integrate our existing PHP website
I have a really ugly legacy database system that I need to integrate with.
I have repositories and services that wrap them. Now I need to integrate caching
I have a current build using teambuild/msbuild that I need to integrate a wix
I need to implement something like this. I was searching over internet, and i
We have a requirement that we need to integrate OpenERP with Drupal . I
I need to integrate some legacy 32-bit code - for which I don't have
I have recently taken on a project in which I need to integrate with

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.