Trolltech Home | Qt-interest Home | Recent Threads | All Threads | Author | Date
All threads index page 10

Qt-interest Archive, March 2002
Problem getting richtext out of QTextEdit


Message 1 in thread

Hello,

  I am having trouble using the QTextEdit class.  I am trying to write a 
rather specialised word processor with this class.  The problem that I am 
having is that if I send in text marked up as "Rich text" I am unable to get 
at the original marked up text.  It seems as though there should be a way to 
do this but I cannot find any information in the documentation from QT.  I 
have included a sample program with this email that illustrates the problem, 
allong with a simplistic makefile that may be useful on a Linux system.  I am 
using QT 3.0, on a laptop running Red Hat 7.1.  Also, I am curious as to why 
I cannot edit the table that is being created?
   In the end I will need to be able to load, edit, save, print, etc files 
using unicode characters from various different languages, and even though 
the sample program is rather simplistic, I have a pretty good start on the 
actual program.  I have used QT for an opengl project for a class that I took 
last semester, but otherwise have very little QT experiance and very little 
GUI experiance so any advice would be welcome, especially where to find 
additional documentation.

Thank you for your time,
John Pitz
QTLIBPATH=/usr/lib/qt/lib
QTINCLUDE=/usr/lib/qt/include
OFILESARE=main.o 



sample : $(OFILESARE) 
	g++ -g -L $(QTLIBPATH) -Wl,-rpath,$(QTLIBPATH) -o sample $(OFILESARE) -lqt
	clear

main.o : main.cpp 
#	moc main.h -o main.moc
	g++  -g -c -I $(QTINCLUDE) -o main.o main.cpp




#include<qtextedit.h>
#include<qapplication.h>
#include<qwidget.h>
#include<qstring.h>

class myTextEdit:public QTextEdit
{
	public:
	  myTextEdit();
	  ~myTextEdit();
};


myTextEdit::myTextEdit():QTextEdit()
{
	QString qs_input;
	qs_input.append("<qt> <table border=1> <tr> <td> 1 </td> <td> 2 </td> </tr>");
	qs_input.append("<tr> <td> One </td> <td> Two </td> </tr> </table> </qt>");

	cout<<"The data going into the QTextEdit is:\n"<<qs_input<<"\n";
	cout.flush();

	append(qs_input);
}

myTextEdit::~myTextEdit()
{
	cout<<"The data coming out of the QTextEdit is:\n"<<text()<<"\n";
	cout<<"Why are they different, and where is the b coming from?\n";
}

int main(int argc, char **argv)
{
  
  	QApplication a(argc, argv);
	myTextEdit qte_text;
	a.setMainWidget(&qte_text);
	qte_text.show();
	a.exec();

	return 0;
}

Message 2 in thread

Newsmail wrote:
> Hello,
> 
>   I am having trouble using the QTextEdit class.  I am trying to write a 
> rather specialised word processor with this class.  The problem that I am 
> having is that if I send in text marked up as "Rich text" I am unable to get 
> at the original marked up text.
> ......

In the sixth paragraph of the QTextEdit documentation,
there is a line that says:

"If you create a new QTextEdit, and want to allow the
user to edit rich text, call setTextFormat(Qt::RichText)
to ensure that the text is treated as rich text."

So, if you add setTextFormat(Qt::RichText) to your
constructor, it will spit out the Rich Text.

-- 
 [ signature omitted ]