Hi, I have a similar problem, but I did put my layout onto a widget, so that's not the mistake.
I created a QGraphicsView with content and it shows up when I use view->show() or view->showMaximized(), but now I want it within the MainWindow (having buttons on the left side) but there is just a blank white area showing up... so here is my code, hope somebody can see the mistake:
This is in MainWindow::MainWindow()
... // creating some items that inherit from QGraphicsItem - like I said, there shouldn't be an error here
// cause the view itself shows when I use it as the main widget
scene.addItem(pa);
view->setBackgroundBrush(red); // the red doesn't even show up in the mainwindow, it's a white space beside my buttons
win->setMinimumSize(desktopWidth, desktopHeight - 10); // tried that to make sure it's not the non-existence of size
layout->addWidget(bw); // my buttons
layout->addWidget(view);
win->setLayout(layout);
QGraphicsScene scene;
... // creating some items that inherit from QGraphicsItem - like I said, there shouldn't be an error here
// cause the view itself shows when I use it as the main widget
scene.addItem(pa);
QGraphicsView *view = new QGraphicsView(&scene);
QBrush red(QColor(250,50,50));
view->setBackgroundBrush(red); // the red doesn't even show up in the mainwindow, it's a white space beside my buttons
QWidget *win = new QWidget(this); //this <=> MainWindow
win->setMinimumSize(desktopWidth, desktopHeight - 10); // tried that to make sure it's not the non-existence of size
QHBoxLayout *layout = new QHBoxLayout();
layout->addWidget(bw); // my buttons
layout->addWidget(view);
win->setLayout(layout);
To copy to clipboard, switch view to plain text mode
Thanks for any help
Uli
Added after 11 minutes:
I don't know if this tells somebody something, but I noticed something weird in general:
Earlier I tried creating the view and its context without using the mainWindow at all.. used view->showMaximized() and everything was perfect.
Now I tried to just show my QGraphicsView from within the MainWindow (so removed the whole part that is after line 10 in my earlier comment, that is QWidget and QLayout) and simply put a view->showMaximized() .. as a result I see my QGraphicsView for a second and then it disappears and I have a white blank area instead of the red background with my content.. could that be the same white area that I see when adding it to the layout ? Is there something wrong with putting my view in the MainWindow ? (IMO it should be fine existing in MainWindow ?)
Bookmarks