I would like to make a QGraphicsView just fit in a QMainWiondw of fixed size. And I need the coordinate of the top left corner to be (0,0). How can I do this?
This is my main function
int main(int argc, char *argv[])
{
QApplication a(argc, argv);
MainWindow window;
window.setFixedSize(1440, 900);
window.show();
return a.exec();
}
This is the MainWindow constructor.
MainWindow::MainWindow(QWidget *parent)
: QMainWindow(parent)
{
view = new QGraphicsView(this);
scene = new QGraphicsScene(0, 0, 1440, 900, this);
view->setScene(scene);
setCentralWidget(view);
drawCoordinate(0,0);
}
There is a scroll appeared. I think it is deal to the title bar.
I don't really mind the size of the QGraphicsView as long as the size of the mainwindow is fixed. But I need the QGraphicsView to fill the whole mainwindow without a scroll bar and the top left corner of the mainwindow is located at (0, 0).
With @tangerine help, I can make the program like this. But there is still space between the main window and the graphic view.
This is what I hope to achieve:
The (0, 0) coordinate starts at the topmost and leftmost of the mainwindow.
view->setAlignment(Qt::AlignLeft | Qt::AlignTop);
– metalfox