Please nominate your Qt Champions for 2021!

QgraphicsView not align to center if setFixedSize

  • When I setFixedSize for my QgraphicsView he get align to the top left corner of the centralwidget, when I don't setFixeSize it's centered but the view is spread on the entire centralwidghet meaning if I set mouseMoveEvent to the (x,y) position it will work for the entire screen even the part of the screen which don't have any QGrpahicsItem paint on.

    some test code I was trying (I was trying to set it inside a layout as well):

    @m_mapView = new MapView(this);
    QGridLayout *mainLayout = new QGridLayout(this);
    mainLayout->setAlignment(m_mapView, Qt::AlignCenter);
    m_mapView->setFixedSize(wPixel, hPixel);@

    • mapView is a custom QGraphicsView, maybe I need to implement something there that will make it align to the center?
    • I know that the default align for QGraphicsView is center...but doesn't seems to work for me

Log in to reply