Results 1 to 10 of 10

Thread: Qt Parent <-> Child Relation When Painting

  1. #1
    Join Date
    Apr 2012
    Location
    Vienna, Austria
    Posts
    17
    Qt products
    Qt4 Qt5
    Platforms
    MacOS X Unix/X11 Windows Android

    Default Qt Parent <-> Child Relation When Painting

    Hello everybody!

    I'm trying to use Qt together with Ogre. Everything worked so far under Linux, but as i recently had to change to my windows machine i encountered this strange Problem:
    All children of my Ogre widget are just plain white.

    windows_probleme_widgets_zeichnen.jpg

    It makes sense as i had to kill the Ogre widget's PaintEngine with:

    Qt Code:
    1. QPaintEngine *editor_engine:: paintEngine() const
    2. {
    3. return 0;
    4. }
    To copy to clipboard, switch view to plain text mode 

    to enable Ogre beeing rendered as "the widget's background".

    As i already said, the exactly same code works under Linux without any troubles.

    Now my question is, how can i give all the child-widgets a own paintEngine - or is there a better way to bring them back to life on windows ? :3

  2. #2
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,359
    Thanks
    3
    Thanked 5,015 Times in 4,792 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: Qt Parent <-> Child Relation When Painting

    We don't know what you did exactly so it's not possible to answer your question in any viable way.
    Your biological and technological distinctiveness will be added to our own. Resistance is futile.

    Please ask Qt related questions on the forum and not using private messages or visitor messages.


  3. #3
    Join Date
    Apr 2012
    Location
    Vienna, Austria
    Posts
    17
    Qt products
    Qt4 Qt5
    Platforms
    MacOS X Unix/X11 Windows Android

    Default Re: Qt Parent <-> Child Relation When Painting

    Qt Code:
    1. #include <QtGui/QApplication>
    2. #include <QPaintEngine>
    3. #include <QWidget>
    4. #include <QPushButton>
    5.  
    6. class myclass : public QWidget
    7. {
    8. public:
    9. myclass()
    10. {
    11. setAttribute(Qt::WA_NoSystemBackground);
    12. setAttribute(Qt::WA_PaintOnScreen);
    13. setWindowFlags( this->windowFlags() | Qt::MSWindowsOwnDC );
    14. setFocusPolicy(Qt::StrongFocus);
    15. }
    16.  
    17. QPaintEngine * paintEngine() const
    18. {
    19. return 0;
    20. }
    21. };
    22.  
    23.  
    24. int main(int argc, char *argv[])
    25. {
    26.  
    27.  
    28. QApplication a(argc, argv);
    29.  
    30. myclass c;
    31. QPushButton* b = new QPushButton( "hi" );
    32. b->setParent( &c );
    33. b->move( 10,10 );
    34. c.show();
    35. c.resize(100,100);
    36.  
    37. return a.exec();
    38. }
    To copy to clipboard, switch view to plain text mode 

    that's what i did ..
    if you want to have the full 2000 lines of the header and source files, well no problem, just tell me if the above isn't enough.
    yet the question is how can i - in this example - reimplement the QPushButton to have it's own paint-routine so it becomes visible ?

  4. #4
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,359
    Thanks
    3
    Thanked 5,015 Times in 4,792 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: Qt Parent <-> Child Relation When Painting

    Does it change anything if you set the Qt::AA_NativeWindows attribute on the application object?
    Your biological and technological distinctiveness will be added to our own. Resistance is futile.

    Please ask Qt related questions on the forum and not using private messages or visitor messages.


  5. #5
    Join Date
    Apr 2012
    Location
    Vienna, Austria
    Posts
    17
    Qt products
    Qt4 Qt5
    Platforms
    MacOS X Unix/X11 Windows Android

    Default Re: Qt Parent <-> Child Relation When Painting

    Nope,
    i tried it on my application and on the example code above

    i just discovered that it is working with an old testing project i created

    it contains the following code:
    Qt Code:
    1. #include <QApplication>
    2. #include <QWidget>
    3. #include <Ogre.h>
    4. #include <QPushButton>
    5.  
    6. int main(int argc, char *argv[])
    7. {
    8. Ogre::Root* ogre_root;
    9. Ogre::RenderWindow* ogre_render_window;
    10. Ogre::SceneManager* ogre_scene_manager;
    11.  
    12. Ogre::Camera* ogre_haupt_kamera;
    13. Ogre::Viewport* ogre_viewport;
    14.  
    15. QApplication app(argc,argv);
    16.  
    17. QWidget* widget = new QWidget();
    18. widget->setAttribute(Qt::WA_NoSystemBackground);
    19. widget->setAttribute(Qt::WA_PaintOnScreen);
    20. widget->setWindowFlags( widget->windowFlags() | Qt::MSWindowsOwnDC );
    21. widget->setFocusPolicy(Qt::StrongFocus);
    22.  
    23. ogre_root = new Ogre::Root();
    24.  
    25. ogre_root->addResourceLocation( "resources", "FileSystem", "General" );
    26.  
    27. Ogre::ResourceGroupManager::getSingleton().initialiseAllResourceGroups();
    28.  
    29. ogre_root->loadPlugin( "ogre_plugins/RenderSystem_GL" );
    30. ogre_root->loadPlugin( "ogre_plugins/Plugin_OctreeSceneManager" );
    31.  
    32. Ogre::RenderSystem* rs = ogre_root->getRenderSystemByName("OpenGL Rendering Subsystem");
    33. if(!(rs->getName() == "OpenGL Rendering Subsystem"))
    34. {
    35. return false; //No RenderSystem found
    36. }
    37. // configure our RenderSystem
    38. rs->setConfigOption("Full Screen", "No");
    39. rs->setConfigOption("VSync", "No");
    40. rs->setConfigOption("Video Mode", "800 x 600 @ 32-bit");
    41.  
    42. ogre_root->setRenderSystem(rs);
    43.  
    44. ogre_render_window = ogre_root->initialise( false, "my 3D");
    45.  
    46. Ogre::NameValuePairList params;
    47. params["useNVPerfHUD"] = "true";
    48.  
    49. //The external windows handle parameters are platform-specific
    50. Ogre::String externalWindowHandleParams;
    51.  
    52. #if defined(Q_WS_WIN)
    53. //positive integer for W32 (HWND handle) - According to Ogre Docs
    54. externalWindowHandleParams = Ogre::StringConverter::toString((unsigned long)(widget->winId()));
    55. #endif
    56.  
    57. #if defined(Q_WS_X11)
    58. //poslong:posint:poslong:poslong (display*:screen:windowHandle:XVisualInfo*) for GLX - According to Ogre Docs
    59. QX11Info info = x11Info();
    60. externalWindowHandleParams = Ogre::StringConverter::toString((unsigned long)(info.display()));
    61. externalWindowHandleParams += ":";
    62. externalWindowHandleParams += Ogre::StringConverter::toString((unsigned int)(info.screen()));
    63. externalWindowHandleParams += ":";
    64. externalWindowHandleParams += Ogre::StringConverter::toString((unsigned long)(widget->winId()));
    65. #endif
    66.  
    67. //Add the external window handle parameters to the existing params set.
    68. #if defined(Q_WS_WIN)
    69. params["externalWindowHandle"] = externalWindowHandleParams;
    70. params["parentWindowHandle"] = externalWindowHandleParams;
    71. #endif
    72.  
    73. #if defined(Q_WS_X11)
    74. params["parentWindowHandle"] = externalWindowHandleParams;
    75. #endif
    76.  
    77. ogre_render_window = ogre_root->createRenderWindow("OgreWindow", 600, 400, false, &params);
    78. ogre_render_window->setActive(true);
    79. ogre_render_window->setVisible(true);
    80.  
    81. ogre_scene_manager = ogre_root->createSceneManager( "OctreeSceneManager" );
    82.  
    83. ogre_haupt_kamera = ogre_scene_manager->createCamera( "haupt_kamera" );
    84. ogre_haupt_kamera->setPosition( Ogre::Vector3(100,100,100) );
    85. ogre_haupt_kamera->lookAt(Ogre::Vector3(0, 0, 0));
    86.  
    87. ogre_haupt_kamera->setNearClipDistance(0.1);
    88.  
    89. if (ogre_root->getRenderSystem()->getCapabilities()->hasCapability(Ogre::RSC_INFINITE_FAR_PLANE))
    90. {
    91. ogre_haupt_kamera->setFarClipDistance(0); // wird eingeschalten wenn die grafikkarte das unterstützt
    92. }
    93.  
    94. ogre_viewport = ogre_render_window->addViewport( ogre_haupt_kamera );
    95. ogre_viewport->setBackgroundColour( Ogre::ColourValue( 0.9, 0.9, 0.9 ) );
    96.  
    97. ogre_haupt_kamera->setAspectRatio( Ogre::Real( ogre_viewport->getActualWidth() ) /
    98. Ogre::Real( ogre_viewport->getActualHeight() ) );
    99.  
    100. ogre_scene_manager->setAmbientLight( Ogre::ColourValue(0.9f, 0.9f, 0.9f) );
    101. ogre_scene_manager->setShadowTechnique( Ogre::SHADOWTYPE_STENCIL_ADDITIVE );
    102. ogre_scene_manager->setShadowColour(Ogre::ColourValue(0.5, 0.5, 0.5));
    103.  
    104. // ogre_scene_manager->setSkyBox( true, "Himmel", 5000 );
    105.  
    106.  
    107. widget->show();
    108. widget->resize(400,300);
    109.  
    110. QPushButton* b = new QPushButton( "hi" );
    111. b->setParent( widget );
    112. b->move( 10,10 );
    113. b->show();
    114.  
    115. return app.exec();
    116. }
    To copy to clipboard, switch view to plain text mode 

    am i blind that i can't find the difference?
    or is it just that the test-project never redraws the ogre-stuff
    *investigating*


    Added after 54 minutes:


    ok ok, now i tried to remove the termination of the paintengine

    Qt Code:
    1. //QPaintEngine *editor_engine:: paintEngine() const
    2. //{
    3. // return 0;
    4. //}
    To copy to clipboard, switch view to plain text mode 

    Now all the child-qwidgets are visible but the ogre content is not.
    As far as i can remember this was the reason why i killed the paintengine of the widget.

    What brings us back to the topic:
    How can i paint children, if the parent qwidget doesn't have a paintEngine ?


    Added after 50 minutes:


    And of course the app's output gets spammed with
    Qt Code:
    1. QPainter::begin: Paint device returned engine == 0, type: 1
    2. QPainter::setPen: Painter not active
    3. QPainter::setBrush: Painter not active
    4. QPainter::setRenderHint: Painter must be active to set rendering hints
    5. QPainter::drawRects: Painter not active
    6. QPainter::setBrush: Painter not active
    7. QPainter::drawRects: Painter not active
    To copy to clipboard, switch view to plain text mode 
    Last edited by axed; 20th April 2012 at 01:50.

  6. #6
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,359
    Thanks
    3
    Thanked 5,015 Times in 4,792 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: Qt Parent <-> Child Relation When Painting

    The point is that Qt::WA_PaintOnScreen only works on X11. Windows will ignore it thus you get a different behaviour on the two platforms. It would be easiest to overcome this problem if you made OGRE paint not on the widget but on an image (e.g. through a pixel buffer or something similar) and then render that image to the widget using regular Qt means.
    Your biological and technological distinctiveness will be added to our own. Resistance is futile.

    Please ask Qt related questions on the forum and not using private messages or visitor messages.


  7. #7
    Join Date
    Apr 2012
    Location
    Vienna, Austria
    Posts
    17
    Qt products
    Qt4 Qt5
    Platforms
    MacOS X Unix/X11 Windows Android

    Default Re: Qt Parent <-> Child Relation When Painting

    Thank you for still being patient with me!

    Just to remind everybody at this point: I'm using atm Windows7.

    When i comment out the setAttribute(Qt::WA_PaintOnScreen); line
    All child-widgets become painted properly - But Ogre does not render at all.
    If i uncomment the line again, all the children are messed up again, but ogre renders just fine.

    Nice to see it only affects X11 ...

    Actually the ogre documentations, examples and their wiki are very ... well .... "imprecise" or "incomplete" and far not as extensive as Qt's docu.
    So it seems that people render ogre's content into the widget by mixing the winid, doing that instead with another buffer looks to me -correct me if i'm wrong, as i'm taking the ogre-doc's quality into account- , like a huge thing to do.
    Also, i would have to restructure some huge parts of my project - which where supposed to be platform-independent.
    It doesn't look much like an option to me, and it doesn't even smell like the "Qt's"-way.
    Isn't there an equivalent of Qt::WA_PaintOnScreen for windows?
    I just can't find one in the Qt-docs.


    Added after 5 minutes:


    just if you're not too familiar with integrating ogre into qt:
    https://ogreaddons.svn.sourceforge.n...OgreWidget.cpp
    Last edited by axed; 20th April 2012 at 10:52.

  8. #8
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,359
    Thanks
    3
    Thanked 5,015 Times in 4,792 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: Qt Parent <-> Child Relation When Painting

    Quote Originally Posted by axed View Post
    doing that instead with another buffer looks to me -correct me if i'm wrong, as i'm taking the ogre-doc's quality into account- , like a huge thing to do.
    I don't know. I guess using an OpenGL backend would be much simpler than DirectX one, maybe you should look into that?

    Also, i would have to restructure some huge parts of my project - which where supposed to be platform-independent.
    I don't think so. You'd only have to change the paint event and add a dedicated method for rendering into the pixmap. The rest shouldn't need to be changed.

    Isn't there an equivalent of Qt::WA_PaintOnScreen for windows?
    If there was, PaintOnScreen would simply be made work on Windows
    Your biological and technological distinctiveness will be added to our own. Resistance is futile.

    Please ask Qt related questions on the forum and not using private messages or visitor messages.


  9. #9
    Join Date
    Apr 2012
    Location
    Vienna, Austria
    Posts
    17
    Qt products
    Qt4 Qt5
    Platforms
    MacOS X Unix/X11 Windows Android

    Default Re: Qt Parent <-> Child Relation When Painting

    As i switched from linux, I'm still using OpenGL // as the rendersystem for ogre - there is no directx involved at all.

    Qt Code:
    1. Ogre::RenderSystem* rs = ogre_root->getRenderSystemByName("OpenGL Rendering Subsystem");
    2.  
    3. if(!(rs->getName() == "OpenGL Rendering Subsystem"))
    4.  
    5. {
    6.  
    7. return false; //No RenderSystem found
    8.  
    9. }
    10.  
    11. // configure our RenderSystem
    12.  
    13. rs->setConfigOption("Full Screen", "No");
    14.  
    15. rs->setConfigOption("VSync", "No");
    16.  
    17. rs->setConfigOption("Video Mode", "800 x 600 @ 32-bit");
    18.  
    19.  
    20.  
    21. ogre_root->setRenderSystem(rs);
    To copy to clipboard, switch view to plain text mode 

    So my problem is, that i have no idea about how i could fetch the ogre-content without embedding it into an widget. And all Ogre+Qt combinations i've seen so far are doing it exactly this way.


    Isn't there an equivalent of Qt::WA_PaintOnScreen for windows?
    If there was, PaintOnScreen would simply be made work on Windows
    true :3

    the only thing that i can imagine atm is to create a hidden widget, where the ogre content gets rendered and i call in my paint events the QWidget::render(...) on that seperate widget.
    But somehow i fell silly as other guys - like in the link i posted above, can archive that stuff without bitchin' around in all those indirections.

  10. #10
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,359
    Thanks
    3
    Thanked 5,015 Times in 4,792 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: Qt Parent <-> Child Relation When Painting

    You should look into something OGRE calls a "hardware buffer". You should be able to force OGRE to render into a pixel buffer (e.g. through QGLPixelBuffer) and then it should be easy to extract its contents and use it in Qt. Unfortunately I'm not an expert on neither OpenGL nor OGRE so I can't help you much with it.
    Your biological and technological distinctiveness will be added to our own. Resistance is futile.

    Please ask Qt related questions on the forum and not using private messages or visitor messages.


Similar Threads

  1. Parent child relationship in Qt
    By TheIndependentAquarius in forum Newbie
    Replies: 18
    Last Post: 14th July 2011, 08:43
  2. Parent-child realtionship
    By AviMittal in forum Qt Programming
    Replies: 3
    Last Post: 25th June 2009, 15:44
  3. parent/child callback
    By mhoover in forum General Programming
    Replies: 2
    Last Post: 24th June 2009, 23:50
  4. Replies: 0
    Last Post: 7th June 2007, 14:15
  5. Parent-child-problems ;)
    By nupul in forum Qt Programming
    Replies: 11
    Last Post: 9th May 2006, 14:03

Tags for this Thread

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.