February 24, 2012

tomas.soltys tomas.soltys
Lab Rat
6 posts

QGLWidget::renderText => incomplete text

 

Hi all,

I am new to the Qt and so far I am enjoying it.
Qt version: 4.7.4

Here is what I am printing on the screen:

  1.   qglColor(QColor("#ffffff"));
  2.   renderText(100,100,QString("Hello world!"));

Everything else (other than text) is being drawn correctly.

But only first three characters “Hel” are being printed.
Can someone point me to an area from where this problem can come from or how to solve it?

Thanks,

Tomas

6 replies

February 24, 2012

shoyeb shoyeb
Lab Rat
99 posts

did u set the font of the text using QFont…

renderText method takes QFont as a parameter….

 Signature 

There is not now, nor has there ever been, nor will there ever be, any programming language in which it is the least bit difficult to write bad code.

February 24, 2012

tomas.soltys tomas.soltys
Lab Rat
6 posts

I did not. Documentation says that in case the font parameter is omitted a default one is used.
However, I have tried to set it as well, but with no effect other than font has changed.
Only first three characters are being drawn.

Is there some hidden limit that could be set or something?

February 24, 2012

tomas.soltys tomas.soltys
Lab Rat
6 posts

I have noticed one more thing.

Even if I use QPainter to draw text, it draws only first three chars as well.

tomas.soltys wrote:
I did not. Documentation says that in case the font parameter is omitted a default one is used.
However, I have tried to set it as well, but with no effect other than font has changed.
Only first three characters are being drawn.

Is there some hidden limit that could be set or something?

February 27, 2012

tomas.soltys tomas.soltys
Lab Rat
6 posts

Yet another observation.

This happens only on my OpenSUSE installation. On Windows 7 full string is being printed.

Tomas

February 29, 2012

tomas.soltys tomas.soltys
Lab Rat
6 posts

I have created a small example. Here is the code which produces this behavior.

  1. #include <QtGui>
  2. #include <QtOpenGL>
  3.  
  4. #include "glwidget.h"
  5.  
  6. GLWidget::GLWidget(QWidget *parent)
  7.      : QGLWidget(QGLFormat(QGL::SampleBuffers), parent)
  8. {
  9. }
  10.  
  11. GLWidget::~GLWidget()
  12. {
  13. }
  14.  
  15. QSize GLWidget::minimumSizeHint() const
  16. {
  17.     return QSize(50, 50);
  18. }
  19.  
  20. QSize GLWidget::sizeHint() const
  21. {
  22.     return QSize(400, 400);
  23. }
  24.  
  25. void GLWidget::initializeGL()
  26. {
  27.     qglClearColor(QColor(0,0,0,255));
  28. }
  29.  
  30. void GLWidget::resizeGL(int width, int height)
  31. {
  32.     glViewport (0, 0, (GLsizei)width, (GLsizei)height);
  33.  
  34.     glLoadIdentity ();
  35.     glMatrixMode (GL_PROJECTION);
  36.     glLoadIdentity ();
  37.  
  38.     GLdouble winRatio = (GLdouble)height/(GLdouble)width;
  39.     glOrtho(-1.0, 1.0, -winRatio, winRatio, -10.0, 10.0);
  40.  
  41.     glMatrixMode (GL_MODELVIEW);
  42. }
  43.  
  44. void GLWidget::paintGL()
  45. {
  46.     glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
  47.     glLoadIdentity();
  48.     glEnable(GL_DEPTH_TEST);
  49.  
  50.     this->qglColor(QColor("#ffffff"));
  51.     this->renderText(0.1,0.1,0.0,QString("1Hello 1"));
  52.     this->renderText(20,20,QString("2Hello 2"));
  53. }

February 29, 2012

shoyeb shoyeb
Lab Rat
99 posts

is it working now?

 Signature 

There is not now, nor has there ever been, nor will there ever be, any programming language in which it is the least bit difficult to write bad code.

 
  ‹‹ [Solved] Qt text rendering issue on windows xp korean version      [Solved] Accessing UI components from another file ››

You must log in to post a reply. Not a member yet? Register here!