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. QGraphicsView scaling
Qt 6.11 is out! See what's new in the release blog

QGraphicsView scaling

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

    Hello,

    I'am playing with QGraphics and I encounter a problem with the following code.
    It is simply a red circle in a scene. Its dimension can be scaled with the "factor" variable.
    The view is scaled in order the circle has always the same size on the screen.

    When factor is 10 I can click the circle, but when factor is 1 It is as the shape was the boundingRect.

    I don't understand this behavior, is there is limit in item size ?

    Thanks a lot,

    Cyril.

    @#include <QtGui>

    float dim = 5e-3;
    float scale = 20000;
    float factor = 1.;

    int main(int argc, char *argv[])
    {
    QApplication app(argc, argv);
    dim = dim * factor;
    scale = scale / factor;

    QGraphicsView *view = new QGraphicsView;
    QGraphicsScene *scene = new QGraphicsScene;
    QRectF rect = QRectF(-dim, -dim, 2*dim, 2*dim);
    QGraphicsEllipseItem *item = new QGraphicsEllipseItem(rect, 0);
    item->setBrush(QBrush(Qt::red));
    item->setFlag(QGraphicsItem::ItemIsSelectable, true);
    item->setFlag(QGraphicsItem::ItemIsMovable, true);
    scene->addItem(item);
    view->scale(scale, scale);
    view->setRenderHints(QPainter::Antialiasing);
    view->setScene(scene);
    view->show();
    return app.exec();
    

    }
    @

    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