【问题标题】:Qgraphicview resizing when windows resizing窗口调整大小时Qgraphicsview调整大小
【发布时间】:2019-05-15 22:09:32
【问题描述】:

我想问你一个我无法解决的问题。 我有一个在第一个主窗口中加载图像的 QApplication。

代码如下:

QGraphicsScene *scene = new QGraphicsScene;
QPixmap pixmap(QString::fromStdString("image.png");
scene->addPixmap(pixmap);
ui->graphview->setScene(scene);
ui->graphview->show();

我正在尝试使图像适应 QGraphivsView 中的缩放比例,即使我调整了窗口大小。

但是,图像在运行时以自己的大小显示,并且在调整窗口大小时该大小不会改变。例如,增加我的窗口不会增加图像大小,而减少也是类似的。

我什至尝试添加以下代码:

ui->graphview->fitInView(pixmap, Qt::KeepAspectRatioByExpanding);

但没有任何效果。

我在下图中为您提供了一个正在发生的事情的示例。

【问题讨论】:

标签: c++ qt scale qgraphicsview dynamic-resizing


【解决方案1】:

我找到了一种方法,但它并不是 100% 令人满意。 我已经替换了 resizeEvent 函数,如下例所示:

void QMainWindows::resizeEvent(QResizeEvent *){
QRectF bounds = ui->graphQSYS->scene()->sceneRect();
ui->graphQSYS->fitInView(bounds, Qt::KeepAspectRatioByExpanding);
ui->graphQSYS->centerOn(bounds.center());
}

但是,在调整大小时,图像质量变得非常糟糕。上面写的文字再也无法阅读了。你知道另一种保持图片质量的方法吗? 非常感谢。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2012-08-02
    • 2016-09-14
    • 1970-01-01
    • 1970-01-01
    • 2011-10-01
    • 1970-01-01
    相关资源
    最近更新 更多