Two question about QGraphicsView , Thanks

  • 1:Why I have to call setHorizontalScrollBarPolicy(Qt:crollBarAlwaysOff) to disable scrollbar, otherwise they will show even the view equal scene.

    2:After call fitInView in resizeEvent, there is always a margin in view. what should I do?

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

    this->myView->setFixedSize(400, 300);


    this->myScene = new QGraphicsScene;


    //why I have to call these function to diable scrollbar,otherwise they will show no matter the view and scene size


    void MainWindow::resizeEvent(QResizeEvent *event)
    //if I call this fitInView, there will be a margin in view. why


  • Hi.

    you might try to replace
    @this->myView->setFixedSize(400, 300);@

    @this->myView->viewport()->setFixedSize(400, 300);@

    The QGraphicsView is not the widget that actually contains the scene, because the QGraphicsView also manages the scrollbars. The scene is drawn in the viewport widget, which is a little smaller than the QGraphicsView.
    I hope this helps. Let me know if it did not.

Log in to reply

Looks like your connection to Qt Forum was lost, please wait while we try to reconnect.