#include <QtGui>
 
public:
 
protected:
 
int leading = fontMetrics.leading();
int height = 0;
qreal widthUsed = 0;
textLayout.beginLayout();
while (1) {
     if (!line.isValid())
         break;
 
     line.setLineWidth(9);
     //line.setNumColumns (1);
     height += leading;
     line.
setPosition(QPoint(0, height
));
     height += line.height();
     widthUsed = qMax(widthUsed, line.naturalTextWidth());
 }
textLayout.endLayout();
    pe.setWidth(4);
    pe.setColor(Qt::red);
    p.setPen(pe);
   textLayout.
draw(&p, 
QPoint(0, 
0));
  }
};
 
int main(int argc, char **argv){
  W w;
  w.show();
  w.resize(300,200);
  return app.exec();
  }
        #include <QtGui>
class W : public QWidget {
public:
  W() : QWidget(){}
protected:
  void paintEvent(QPaintEvent *e){
QTextLayout textLayout( "Hello How are you!");
QFontMetrics fontMetrics(QApplication::font());
int leading = fontMetrics.leading();
int height = 0;
qreal widthUsed = 0;
textLayout.beginLayout();
while (1) {
     QTextLine line = textLayout.createLine();
     if (!line.isValid())
         break;
     line.setLineWidth(9);
     //line.setNumColumns (1);
     height += leading;
     line.setPosition(QPoint(0, height));
     height += line.height();
     widthUsed = qMax(widthUsed, line.naturalTextWidth());
 }
textLayout.endLayout();
    QWidget::paintEvent(e);
    QPainter p(window());
    QPen pe = p.pen();
    pe.setWidth(4);
    pe.setColor(Qt::red);
    p.setPen(pe);
   textLayout.draw(&p, QPoint(0, 0));
  }
};
int main(int argc, char **argv){
  QApplication app(argc, argv);
  W w;
  w.show();
  w.resize(300,200);
  return app.exec();
  }
To copy to clipboard, switch view to plain text mode 
  I am getting the output as attachments;
but I wants as
	
		
			
			
				H
e
l
l
o
H
o
w
a
r
e
y
o
u
!
			
		
 
	 
 What should I do in code for this;
				
			
Bookmarks