[Qt-interest] FieldWidth issue

Atlant Schmidt aschmidt at dekaresearch.com
Thu Apr 21 13:09:33 CEST 2011


Sujan:

  Your example isn't set in a monospaced font so it's a bit hard
  to understand what you mean, but aren't you faced with the
  problem that everything that passes through the "<<" operator
  is a "field"? And each and every one of those fields will have
  the attributes applied?

  So the numbers you write, the spaces you write, and the newline
  character your write are all going to go into their own 20-character-
  wide, centered fields, aren't they? This probably isn't what you want.

  You may want to consider the example from within

    http://doc.qt.nokia.com/latest/qtextstream.html#details


                                            Atlant

Detailed Description

The QTextStream class provides a convenient interface for reading and writing text.

QTextStream can operate on a QIODevice<http://doc.qt.nokia.com/latest/qiodevice.html>, a QByteArray<http://doc.qt.nokia.com/latest/qbytearray.html> or a QString<http://doc.qt.nokia.com/latest/qstring.html>. Using QTextStream's streaming operators, you can conveniently read and write words, lines and numbers. For generating text, QTextStream supports formatting options for field padding and alignment, and formatting of numbers. Example:

 QFile data("output.txt");

 if (data.open<http://doc.qt.nokia.com/latest/qfile.html#open>(QFile::WriteOnly | QFile::Truncate)) {

     QTextStream out(&data);

     out << "Result: " << qSetFieldWidth(10) << left << 3.14 << 2.7;

     // writes "Result: 3.14      2.7       "

 }

________________________________
From: qt-interest-bounces+aschmidt=dekaresearch.com at qt.nokia.com [mailto:qt-interest-bounces+aschmidt=dekaresearch.com at qt.nokia.com] On Behalf Of Sujan Dasmahapatra
Sent: Thursday, April 21, 2011 05:49
To: qt-interest at trolltech.com
Subject: [Qt-interest] FieldWidth issue

Dear Friends I am not able to align my set of number in a symmetric manner. E.g
I have
Standards    Special

0.2232322
2.4343433                   0.323232

How can I set them properly arranged some thing like this
Standards             Special

0.2232322
2.4343433              0.323232

I am trying like this
QTextStrea in(&file);
in.setFieldWidth(20);
in.setFieldAlignment(QTextStream::AlignCenter);

for(int i=0; i<2; i++)
in << n1 << "   "  << n2 << "\n";;

But I am not getting correct results. Thanks sujan

Kind Regards,


Sujan Dasmahapatra
Project Leader, Aero Group
Aero Group
Tel    +91 80 66470248
Mob
sdh at lmwindpower.com<mailto:%25EMAIL%25>

LM Wind Power Blades
lmwindpower.com

Together we capture the wind to power a cleaner world
________________________________

This e-mail and any attachments are confidential. If you are not the named or intended recipient, please notify the sender immediately and do not disclose the contents to any other person, use it for any purpose, or store or copy the information in any medium. Any unauthorized disclosure, use or storage is prohibited and might be unlawful.


Click here<https://www.mailcontrol.com/sr/z+AYVKAkhjHTndxI!oX7Us7Qlo!t9IHthrw7qYrqHBG6eE6ScLFMFWR1180DGDRLh9ZcYbjPzV4LtzovJ!KJwA==> to report this email as spam.

________________________________
This e-mail and the information, including any attachments, it contains are intended to be a confidential communication only to the person or entity to whom it is addressed and may contain information that is privileged. If the reader of this message is not the intended recipient, you are hereby notified that any dissemination, distribution or copying of this communication is strictly prohibited. If you have received this communication in error, please immediately notify the sender and destroy the original message.

Thank you.

Please consider the environment before printing this email.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.qt-project.org/pipermail/qt-interest-old/attachments/20110421/88e61ca6/attachment.html 


More information about the Qt-interest-old mailing list