小编use*_*725的帖子

QGraphicsView滚动和图像缩放/裁剪

我希望在我的QGraphicsView中有一个背景图像,它总是按比例缩放(并在必要时裁剪)到视口的大小,没有滚动条,也没有用键盘和鼠标滚动.下面的示例是我在视口中缩放和裁剪图像的操作,但我使用随机值进行从以太中拉出的裁剪.我想要一个合理的解决方案?

MainWindow::MainWindow(QWidget *parent) :
    QMainWindow(parent),
    ui(new Ui::MainWindow)
{

    ui->setupUi(this);
    scene = new QGraphicsScene(this);

    ui->graphicsView->resize(800, 427); 
    // MainWindow is 800x480, GraphicsView is 800x427. I want an image that
    // is the size of the graphicsView.

    ui->graphicsView->setHorizontalScrollBarPolicy(Qt::ScrollBarAlwaysOff);
    ui->graphicsView->setVerticalScrollBarPolicy(Qt::ScrollBarAlwaysOff);
    // the graphicsView still scrolls if the image is too large, but 
    // displays no scrollbars. I would like it not to scroll (I want to 
    // add a scrolling widget into the QGraphicsScene later, on top of
    // the background image.)


    QPixmap *backgroundPixmap …
Run Code Online (Sandbox Code Playgroud)

qt scale qpixmap qimage qgraphicsview

5
推荐指数
1
解决办法
1万
查看次数

标签 统计

qgraphicsview ×1

qimage ×1

qpixmap ×1

qt ×1

scale ×1