Results 1 to 5 of 5

Thread: QGraphicsScene::addWidget on MAC OS X 10.5.8

  1. #1
    Join Date
    Aug 2009
    Location
    Reading, UK
    Posts
    4
    Thanks
    1
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11 Windows

    Default QGraphicsScene::addWidget on MAC OS X 10.5.8

    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
    Qt Code:
    1. m_gs = new DocScene(); // derived from QGraphicsScene
    2. QGridLayout *gvBackLayout = new QGridLayout;
    3. // The layout is filled with (many) QLabels created out QPixmaps using
    4. ---
    5. gvBackLayout->addWidget(QLabel* , ...);
    6. ---
    7. QWidget * backform = new QWidget; // In the end a new Widget is created
    8. backform->setLayout(gvBackLayout); // and the layout created before
    9. // is assigned to it
    10. m_gpw = m_gs->addWidget(backform); // the newly created widget
    11. // is assigned to the scene
    12. ui.graphicsView->setScene(m_gs); // scene assigned to the view
    To copy to clipboard, switch view to plain text mode 

    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

  2. #2
    Join Date
    Jan 2006
    Location
    Frankfurt
    Posts
    500
    Thanks
    1
    Thanked 52 Times in 52 Posts
    Platforms
    MacOS X Unix/X11

    Default Re: QGraphicsScene::addWidget on MAC OS X 10.5.8

    It's nice to be important but it's more important to be nice.

  3. The following user says thank you to axeljaeger for this useful post:

    marcomas (19th August 2009)

  4. #3
    Join Date
    Aug 2009
    Location
    Reading, UK
    Posts
    4
    Thanks
    1
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11 Windows

    Default Re: QGraphicsScene::addWidget on MAC OS X 10.5.8

    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.

  5. #4
    Join Date
    Aug 2009
    Location
    Reading, UK
    Posts
    4
    Thanks
    1
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11 Windows

    Default Re: QGraphicsScene::addWidget on MAC OS X 10.5.8

    Quote Originally Posted by axeljaeger View Post
    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.

  6. #5
    Join Date
    Aug 2009
    Location
    Reading, UK
    Posts
    4
    Thanks
    1
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11 Windows

    Default Re: QGraphicsScene::addWidget on MAC OS X 10.5.8 - SOLVED

    Qt Code:
    1. m_gs = new DocScene(); // derived from QGraphicsScene
    2. QGridLayout *gvBackLayout = new QGridLayout;
    3. // The layout is filled with (many) QLabels created out QPixmaps using
    4. ---
    5. gvBackLayout->addWidget(QLabel* , ...);
    6. ---
    7. QWidget * backform = new QWidget; // In the end a new Widget is created
    8. backform->setLayout(gvBackLayout); // and the layout created before
    9. // is assigned to it
    10. m_gpw = m_gs->addWidget(backform); // the newly created widget
    11. // is assigned to the scene
    12. ui.graphicsView->setScene(m_gs); // scene assigned to the view
    To copy to clipboard, switch view to plain text mode 
    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
    Qt Code:
    1. m_gs = new DocScene(); // derived from QGraphicsScene
    2. QGridLayout *gvBackLayout = new QGridLayout;
    3. QWidget * backform = new QWidget; // In the end a new Widget is created
    4. backform->setLayout(gvBackLayout); // and the layout created before
    5. // is assigned to it
    6. m_gpw = m_gs->addWidget(backform); // the newly created widget
    7. // is assigned to the scene
    8. // The layout is filled with (many) QLabels created out QPixmaps using
    9. ---
    10. gvBackLayout->addWidget(QLabel* , ...);
    11. ---
    12. ui.graphicsView->setScene(m_gs); // scene assigned to the view
    To copy to clipboard, switch view to plain text mode 

    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.

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Digia, Qt and their respective logos are trademarks of Digia Plc in Finland and/or other countries worldwide.