[Qt-interest] Adding a QPushButton to a QgraphicsScene

Andreas Unger andi.unger05 at gmail.com
Tue Aug 18 14:59:40 CEST 2009


Hi all,

First of all, I'm trying to create a window with a bunch of buttons (about
four) whose position on the screen changes depending on various factors. I
also hope to add an animated navigation panel with about four buttons as
well. The idea is that when you click on one of the initial buttons, an
animated navigation panel appears with more buttons that have additional
options. First of all QGraphicsView/QGraphicsScene is the best way to do
this right?

I'm trying to add a QPushButton  to a QGraphicsScene as follows:

 MainWindow::MainWindow(QWidget *parent)

: QGraphicsView(parent)

{

this->setGeometry(0, 0, 800, 600);

this->scene = new QGraphicsScene(this);

this->scene->setSceneRect(0, 0, 800, 600);

QPushButton *button = new QPushButton;

QGraphicsProxyWidget *proxy = this->scene->addWidget(button);

proxy->setPos(300, 200);

setScene(scene);

}

I'm using a QPushButton because I need to style it (set background image
etc)

The interesting thing here is that if I set the bounding rectangle of the
scene to a large size (say, 800 x 600) that results in vertical and
horizontal scrollbars appearing on the sides of the window, the button
appears on the window as soon as the window is loaded up, and works
correctly. If I set it to a smaller size (e.g 400 x 200) hence scrollbars
aren't automatically added to the window, the button appears briefly while
the window is loading and disappears. The button only reappears when I
resize the window. This doesn't happen when the scene bounding rectangle is
large (800 x 600) but it does happen when I do setFrameStyle(QFrame::NoFrame).



Why this behavior? Why does the pushbutton disappear when the window loads
up? Is there a step/directive that I'm missing?

Cheers,
Andreas
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.qt-project.org/pipermail/qt-interest-old/attachments/20090818/fc5c35da/attachment.html 


More information about the Qt-interest-old mailing list