Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8976869
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 15, 20262026-06-15T19:14:36+00:00 2026-06-15T19:14:36+00:00

So I have program which is a Qt App. I have some basic Qt

  • 0

So I have program which is a Qt App. I have some basic Qt GUI on the outside but then I have a Qt widget that makes use of OpenSceneGraph to render a 3D scene. To make things more complicated inside that screen I have a HUD that toggles on and off. This HUD consists of some graphic elements and then a Qt Widget rendered to a texture.

I basically have that working however I am having some size issues within the HUD/Qt Widget. When I first toggle the HUD to visible the Qt Widget is there but way too big. I can change the size but regardless, the first time I press a key the Qt Widget is auto re-sized to fit in the textured area I give it (which is what I expect) but this auto re-sized widget doesn’t fit the area correctly. Its impossible to read the table that the widget contains.

To help I have two screen shots. The first is before I type a key:
http://cerrnim.com/wp-content/uploads/2012/12/before.png
And the second is after I type a key:
http://cerrnim.com/wp-content/uploads/2012/12/after.png

Additionally here are some code fragments showing how I create the HUD. Its of course a part of a much larger program but hopefully this is enough information.

/* AUX function to create HUD geo. */                                           
osg::Geode* HUDGeometry( int x1, int y1, int x2, int y2,                        
    std::string model, HUDEvents event, NetworkViewer* viewer ) {               
  osg::Geometry* quad = osg::createTexturedQuadGeometry(osg::Vec3(x1,y1,0),     
                          osg::Vec3(x2-x1,0,0), osg::Vec3(0,y2-y1,0), 1, 1);    
  osg::Geode* geode = new osg::Geode( ) ;                                       

  geode->setName( model ) ;                                                     
  geode->setUserData( new HUDEvent( event, viewer ) ) ;                         

  osg::Texture2D* HUDTexture = new osg::Texture2D();                            
  HUDTexture->setDataVariance(osg::Object::DYNAMIC);                            
  osg::Image* hudImage = osgDB::readImageFile(model);                           
  HUDTexture->setImage(hudImage);                                               
  geode->getOrCreateStateSet()->setTextureAttributeAndModes(                    
    0, HUDTexture, osg::StateAttribute::ON);                                    

  geode->addDrawable( quad ) ;                                                  

  return geode ;                                                                
}      

/* Creates the HUD but does not display it yet. */                              
void NetworkViewer::initHUD( ) {                                                
  osg::MatrixTransform* mt = new osg::MatrixTransform;                          

  osg::Camera* hudCamera = new osg::Camera;                                     
  hudCamera->setReferenceFrame(osg::Transform::ABSOLUTE_RF);                    
  hudCamera->setViewMatrix(osg::Matrix::identity());                            
  //hudCamera->setProjectionResizePolicy(osg::Camera::FIXED);                   
  hudCamera->setProjectionMatrixAsOrtho2D(0,100,0,100);                         
  hudCamera->setClearMask(GL_DEPTH_BUFFER_BIT);                                 
  hudCamera->setRenderOrder(osg::Camera::POST_RENDER);                          
  hudCamera->setAllowEventFocus(true);                                          

  QWidget* widget = new QWidget;                                                
  layout = new QVBoxLayout( ) ;                                                 
  widget->setLayout(layout);                                                    
  widget->layout()->addWidget(((GUI*)view)->getTabs( ));                        
  //widget->setGeometry(0, 0, 500, 400);                                        

  osg::ref_ptr<osgQt::QWidgetImage> widgetImage = new osgQt::QWidgetImage(widget);

  osg::Geometry* quad = osg::createTexturedQuadGeometry(osg::Vec3(30,32,0),     
                                  osg::Vec3(40,0,0), osg::Vec3(0,35,0), 1, 1);  
  osg::Geode* geode = new osg::Geode;                                           
  geode->addDrawable(quad);                                                     

  osg::Texture2D* texture = new osg::Texture2D(widgetImage.get());              
  texture->setResizeNonPowerOfTwoHint(false);                                   
  texture->setFilter(osg::Texture::MIN_FILTER,osg::Texture::LINEAR);            
  texture->setWrap(osg::Texture::WRAP_S, osg::Texture::CLAMP_TO_EDGE);          
  texture->setWrap(osg::Texture::WRAP_T, osg::Texture::CLAMP_TO_EDGE);          
  mt->getOrCreateStateSet()->setTextureAttributeAndModes(0, texture, osg::StateAttribute::ON);

  mt->addChild(hudCamera);                                                      
  osgViewer::InteractiveImageHandler* handler =                                 
    new osgViewer::InteractiveImageHandler(widgetImage.get(), texture, hudCamera);

  mt->getOrCreateStateSet()->setMode(GL_LIGHTING, osg::StateAttribute::OFF);    
  mt->getOrCreateStateSet()->setMode(GL_BLEND, osg::StateAttribute::ON);        
  mt->getOrCreateStateSet()->setRenderingHint(osg::StateSet::TRANSPARENT_BIN);  
  mt->getOrCreateStateSet()->setAttribute(new osg::Program);                    

  quad->setEventCallback(handler);                                              
  quad->setCullCallback(handler);                                               

  hudCamera->addChild( geode ) ;                                                
  hudCamera->addChild( HUDGeometry(73,73,75,75,                                 
    "models/quit.png", EXIT_OBJ, this ));                                       
  hudCamera->addChild( HUDGeometry(25,25,75,75,                                 
    "models/hud.png", NO_EVENT, this ));           

  osg::Group* overlay = new osg::Group;                                         
  overlay->addChild(mt);                                                        

  root->addChild(overlay);                                                      
  HUD = hudCamera ;                                                             
  disableHUD( ) ;                                                               
}
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-15T19:14:37+00:00Added an answer on June 15, 2026 at 7:14 pm

    I think the main problem is that you do not adapt the dimensions of the widget to the dimensions of the quad you render it on.

    I’m not sure what QWidgetImage is doing internally, but I guess it’s just rendering the widget onto a canvas of appropriate size and convert the result into an image. In your code you map the complete image (regardless of its dimension or aspect ration) onto that quad. If you want the widget to fit the quad you need to resize the widget before creating an image of it.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have enrolled in the iOS developer's program. I've developed an app which I
I have a program which creates JButtons which are then added to a JPanel
I have a program which dynamically generates a GUI. I don't know how many
I have an app for a radio program which includes a number of phone
I have an app which will type text on mouse point; even if that
i have written a java program which currently runs as a desktop app, it
I have created a WCF service which does not use the app.config to configure
I have a very basic program which displays a standard Textview and a extended
I have a small VB6 app in which I use the Shell command to
I have an iOS app which gets some JSON from a server (in the

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.