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. QGraphicsViewWhen the QGraphicsView ‘s scale function is enlarged enough, the rendered QGraphicsPixmapItem image will extend beyond the pixel grid.
Qt 6.11 is out! See what's new in the release blog

QGraphicsViewWhen the QGraphicsView ‘s scale function is enlarged enough, the rendered QGraphicsPixmapItem image will extend beyond the pixel grid.

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

    947a62d6-6f89-4ebd-bf34-bd314ff998d1-image.png

    ui->graphicsView->setRenderHint(QPainter::Antialiasing, false);
    drawWangGe();
    drawTuoYuan();
    ui->graphicsView->setScene(&scene);
    ui->graphicsView->show();

    void QGraphicsViewForm::wheelEvent(QWheelEvent *event)
    {
    if (event->angleDelta().y() > 0)
    {
    scale(1.1, 1.1);
    update();
    }
    else
    {
    scale(1/1.1, 1/1.1);
    update();
    }
    }

    void MainWindow::drawWangGe()
    {
    int width=800;
    int height=600;
    scene.setSceneRect(0, 0, width,height);
    int gridWidth = width;
    int gridHeight = height;
    int numOfColumns = width;
    int numOfRows = height;
    QPen pen(Qt::red);
    pen.setWidthF(1);
    pen.setCosmetic(true);
    pen.setStyle(Qt::SolidLine);
    double cellWidth = gridWidth / static_cast<double>(numOfColumns);
    double cellHeight = gridHeight / static_cast<double>(numOfRows);
    for (int row = 0; row <= numOfRows; ++row)
    {
    double x1 = 0;
    double y1 = row * cellHeight;
    double x2 = gridWidth;
    double y2 = row * cellHeight;
    QGraphicsLineItem* line = new QGraphicsLineItem(x1, y1, x2, y2);
    line->setPen(pen);
    scene.addItem(line);
    line->setZValue(1);
    }
    for (int column = 0; column <= numOfColumns; ++column)
    {
    double x1 = column * cellWidth;
    double y1 = 0;
    double x2 = column * cellWidth;
    double y2 = gridHeight;
    QGraphicsLineItem* line = new QGraphicsLineItem(x1, y1, x2, y2);
    line->setPen(pen);
    scene.addItem(line);
    line->setZValue(1);
    }
    }

    void MainWindow::drawTuoYuan()
    {

    QPixmap pixmap(200, 150);
    pixmap.fill(Qt::transparent); 
    QPainter painter(&pixmap);
    painter.setRenderHint(QPainter::Antialiasing, false);
    painter.setBrush(Qt::blue); 
    painter.setPen(Qt::blue);
    painter.drawEllipse(0, 0, 200, 150);
    painter.end();
    QGraphicsPixmapItem* pixmapItem = new QGraphicsPixmapItem;
    pixmapItem->setPixmap(pixmap);
    pixmapItem->setZValue(0.5);
    pixmapItem->setPos(QPointF(300,300));
    scene.addItem(pixmapItem);
    

    }

    When the above code is incorporated into the project and enlarged to a certain extent, it will produce the phenomenon as shown in my screenshot. How can this be resolved?

    1 Reply Last reply
    0
    • Q Offline
      Q Offline
      qter1234
      wrote on last edited by
      #2

      This issue has been resolved in version 6.8! Thank you for your attention!

      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