PDA

View Full Version : QGraphicsScene and QGraphicsView



rossd
24th April 2007, 18:47
I could be missing something dreadfully obvious here, but....

I have a plugin that creates a QGraphicsScene object and is attached to the QGraphicsView created in the main application. Through the plugin (from the context of the QGraphicsScene object), I want to create a QRadioButton that is attached to the underlying QGraphicsView.

QList<QGraphicsView *>& Views = views();
if(Views.size() == 0)
{
//safety code
}
//We can assume that the Scene (this) is connected to one and only one view.
QRadioButton* pButton = new QRadioButton("Text", Views[0]);

This does not compile on VS 2005 (Qt 4.2.1), the compiler complaining that QGraphicsView* and QWidget* are unrelated pointers. g++ on Mac whines similarily.

According to the docs, the inheritance tree looks like:
QGraphicsView <- QAbstractScrollArea <- QFrame <- QWidget

According to my understanding of C++ this is an acceptable conversion.

Is there something I'm missing, is the documentation correct or what?

Ross

Bitto
24th April 2007, 20:03
Can you show the full source, please? At least including the function signature. :-)

rossd
25th April 2007, 14:43
Problem solved.

Running the source through the preprocessor indicated that the QGraphicsView pointer was resolved through a forward reference in one of the header files. The compiler had no idea of the inheritance tree. As soon as I added:

#include <QGraphicsView>

to the source file, all was right with the world once again.

Sorry for posting because of my sloppiness....

We now return you to your regularily scheduled real problems.

Ross