PDA

View Full Version : QGraphicsScene::addWidget on MAC OS X 10.5.8



marcomas
18th August 2009, 19:38
Hi all,

I am trying to solve a problem and, after a long and unsuccessful research in forums and guides, I decided to post it on this forum.
I don't think that there is already an answer here; however, if there is, please accept my apology and kindly indicate to me a link to it.

The application I am developing has to run on MS Windows, Mac OS X and (later) Linux.
My development environments:


Qt 4.5.2 on Windows XP, Vista, 7RC (Windows, for brevity) with MinGW
Qt 4.5.2 on MAC OS X 10.5.8 (latest Mini Mac)


The application runs perfectly on Windows XP. However, I have a problem on OS X as the scene doesn't show the widget in it correctly.
It has to be said that the widget has a layout containing many, many pixmaps to create a dynamic scene according to user preferences.
When rendered, the size of the scene under the view corresponds to the size of the layout and the scrollbars for the view appear as they do on Windows. However, the actual picture is much smaller and under no circumstances exceeds the size of the view.

I am pretty sure that what I am doing is textbook stuff (at least on 4.5, but that's the only version of Qt I have some experience on) and I might have even written my code out of some example from books or documentation.

Here comes the skeleton of my code


m_gs = new DocScene(); // derived from QGraphicsScene
QGridLayout *gvBackLayout = new QGridLayout;
// The layout is filled with (many) QLabels created out QPixmaps using
---
gvBackLayout->addWidget(QLabel* , ...);
---
QWidget * backform = new QWidget; // In the end a new Widget is created
backform->setLayout(gvBackLayout); // and the layout created before
// is assigned to it
m_gpw = m_gs->addWidget(backform); // the newly created widget
// is assigned to the scene
ui.graphicsView->setScene(m_gs); // scene assigned to the view


I would be extremely grateful to anyone who could indicate to me what I am doing wrong, if anything, or possible alternatives.

Thanks in advance

Marco

axeljaeger
18th August 2009, 23:15
Maybe you suffer from this bug?
http://qt.nokia.com/developer/task-tracker/index_html?method=entry&id=255798

marcomas
19th August 2009, 00:04
AxelJaeger,

Thank you for your reply.

It might be, at least a different way of the bug to show itself.

I am using the Cocoa version of the libraries for OS X, as I don't need backward compatibility for previous versions of OS X/graphic environment. Therefore, according to your link, the application should not be affected, as that bug only shows on Carbon.

I can only say that this part of the libraries looks a bit "young" on MAC OS X, possibly, but this is just a wild guess, with a small community of developers to test it thoroughly.

As an alternative, I have used the QGraphicsGridLayout and all what goes with it according to the manuals and examples on them. It works on MAC, but it's apparently not very memory efficient and it makes the application crash with but a few items on the scene.

marcomas
19th August 2009, 01:17
Maybe you suffer from this bug?
http://qt.nokia.com/developer/task-tracker/index_html?method=entry&id=255798

Just as a curiosity, I have managed to compile and run (only on MAC) the example reported in your post.
I can confirm that even on 4.5.2 (Cocoa binary libraries) I witnessed an odd behaviour, actually even worse than the one on the bug report.

Indeed, both widgets (QLineEdit1 and 2) disappear after a second.
Should it be useful, I am ready to report it to Qt/Nokia, although, as a beginner, I am not familiar with the process and any indication would be welcome.

Thank you again.

marcomas
23rd August 2009, 20:37
m_gs = new DocScene(); // derived from QGraphicsScene
QGridLayout *gvBackLayout = new QGridLayout;
// The layout is filled with (many) QLabels created out QPixmaps using
---
gvBackLayout->addWidget(QLabel* , ...);
---
QWidget * backform = new QWidget; // In the end a new Widget is created
backform->setLayout(gvBackLayout); // and the layout created before
// is assigned to it
m_gpw = m_gs->addWidget(backform); // the newly created widget
// is assigned to the scene
ui.graphicsView->setScene(m_gs); // scene assigned to the view

For reason unknown to me, it looks as if the setting of the layout (gvBackLayout) to the widget (backform) and the addition of the widget to the scene has to be done before the actual entry of the objects in the layout, that is


m_gs = new DocScene(); // derived from QGraphicsScene
QGridLayout *gvBackLayout = new QGridLayout;
QWidget * backform = new QWidget; // In the end a new Widget is created
backform->setLayout(gvBackLayout); // and the layout created before
// is assigned to it
m_gpw = m_gs->addWidget(backform); // the newly created widget
// is assigned to the scene
// The layout is filled with (many) QLabels created out QPixmaps using
---
gvBackLayout->addWidget(QLabel* , ...);
---
ui.graphicsView->setScene(m_gs); // scene assigned to the view


The only drawback is that the performance on Carbon, in my configuration, are just unacceptable. QtCore in this case apparently allocates a lot of memory for internal use and it takes a lot of time to release it.
With Cocoa the situation is much better, still slower compared to the Windows and Linux versions, but adequate.

I hope it helps.