Important: Please read the Qt Code of Conduct -

QMainWindow.resize prevent QGraphicsView.resize

  • QMainWindow.resize will auto resize QGraphicsView to fit parent, how to prevent ?

    void MainWindow::open(QString filepath)
        QPixmap pixmap(filepath);
        QGraphicsPixmapItem *GPI = scene->addPixmap(pixmap);
        GPI->setFlags(QGraphicsItem::ItemIsSelectable | QGraphicsItem::ItemIsMovable);
        scene->setSceneRect(0, 0, pixmap.width(), pixmap.height());

  • @sonichy
    If your QGraphicsView is inside a QLayout, this layout automatically position and resize all child widgets.
    But you can break the resize feature by setup a fixed Size of a widget.

    setFixedHeight(int h)
    setFixedWidth(int w)
    setFixedSize(const QSize &s)
    setFixedSize(int w, int h)

  • @KillerSmath Yes, child widget with no layout will be not auto resize with parent !
    But the scrollbar do not display !

Log in to reply