PDA

View Full Version : scrollbars in MaximumSize QGraphicsView



captiva
17th February 2009, 09:24
TOPIC MOVED TO QT PROGRAMMING FORUM (please respond there)

I have a problem with setting the maximumsize of a qgraphicsview.

I do not want any background canvas area to be visible in the qgraphicsview, so when the window is sized sufficiently large, it should be as in below picture (except without scrollbars.)

For smaller window sizes, the view can be smaller and scrollbars are required.

The problem is, I cannot get the scrollbars to disappear for a maxed window, where the maximum qgraphicsview size is limited to the views bounding rectangle:

http://www.qtcentre.org/forum/picture.php?albumid=5&pictureid=26


MyMain::MyMain(QWidget *parent):QMainWindow(parent)
{
QIcon OpenIcon = this->style()->standardIcon(QStyle::SP_DirOpenIcon, 0, this);

QAction *quit = new QAction("&Quit", this);
QAction *open = new QAction("&Open", this);

QMenu *file = this->menuBar()->addMenu("&File");
file->addAction(open);
file->addAction(quit);

QToolBar *toolbar = addToolBar("main toolbar");
QAction *open2 = toolbar->addAction(OpenIcon, "Open File");
toolbar->addSeparator();

scene = new QGraphicsScene();
scene->addText("Hello, world!",QFont("Helvetica [Cronyx]", 100));
view = new QGraphicsView(scene, this);
scene->itemsBoundingRect();

view->setContentsMargins ( 0,0,0,0 );
view->setMaximumSize(view->sceneRect().width()+1,view->sceneRect().height()+1);
//view->setMaximumSize(view->maximumViewportSize()); /* also does not work*/

this->setCentralWidget(view);
this->resize(800,300);
}