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

Qt-interest Archive, February 2007
QTextEdit::setTextFormat, anyone?

Pages: Prev | 1 | 2 | Next

Message 1 in thread

Hi,

the docs of QTextEdit contain the methods setTextFormat and textFormat
in the section 'Member Function Documentation', but not in 'Public
Functions' summary. I assume this method doesn't exist anymore and it's
a doc bug. Right? And if so, is there another way of configuring a text
edit so that it doesn't produce HTML-tagged text?

Thanks,
M

--
 [ signature omitted ] 

Message 2 in thread

On 07.02.07 12:19:47, Martin wrote:
> the docs of QTextEdit contain the methods setTextFormat and textFormat
> in the section 'Member Function Documentation', but not in 'Public
> Functions' summary. I assume this method doesn't exist anymore and it's
> a doc bug. Right?

I can't see any doc bug. I guess you're talking about Qt3 here, because
Qt4 QTextEdit doesn't have this property at all (except maybe in the
Qt3support classes) and I see a public slot setTextFormat, as well as
the documented property and a getter function. Note public slots are
also public member functions, they are in a separate section because you
can connect signals to them, which is not possible with the other public
members.

Andreas

-- 
 [ signature omitted ] 

Message 3 in thread

"Andreas Pakulat" <apaku@xxxxxx> wrote in message 
news:20070207113554.GA21225@xxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
> On 07.02.07 12:19:47, Martin wrote:
>> the docs of QTextEdit contain the methods setTextFormat and textFormat
>> in the section 'Member Function Documentation', but not in 'Public
>> Functions' summary. I assume this method doesn't exist anymore and it's
>> a doc bug. Right?
>
> I can't see any doc bug. I guess you're talking about Qt3 here, because
> Qt4 QTextEdit doesn't have this property at all (except maybe in the
> Qt3support classes) and I see a public slot setTextFormat, as well as
> the documented property and a getter function. Note public slots are
> also public member functions, they are in a separate section because you
> can connect signals to them, which is not possible with the other public
> members.

With Qt4 on windows, intellisense insists on popping up setTextFormat()
for some classes even though it doesn't exist except in Qt3Support.
I don't remember if it does it for QTextEdit but it does for QLabel.
Maybe that's what he means... 


--
 [ signature omitted ] 

Message 4 in thread

Andreas Pakulat wrote:
> On 07.02.07 12:19:47, Martin wrote:
>> the docs of QTextEdit contain the methods setTextFormat and textFormat
>> in the section 'Member Function Documentation', but not in 'Public
>> Functions' summary. I assume this method doesn't exist anymore and it's
>> a doc bug. Right?
> 
> I can't see any doc bug. I guess you're talking about Qt3 here, because
> Qt4 QTextEdit doesn't have this property at all (except maybe in the
> Qt3support classes) and I see a public slot setTextFormat, as well as
> the documented property and a getter function. Note public slots are
> also public member functions, they are in a separate section because you
> can connect signals to them, which is not possible with the other public
> members.
> 
> Andreas
> 


Uuuuh-kay. So the assistant lists all members, Q3Support or not, in the
same section. I was not aware of that. I'd say that is one giant bug
because the doc tells you there is a method that doesn't exist.

Nonetheless, any idea how I can make the Qt4 text edit use plain text only?

M

--
 [ signature omitted ] 

Message 5 in thread

On 07.02.07 13:28:12, Martin wrote:
> Andreas Pakulat wrote:
> > On 07.02.07 12:19:47, Martin wrote:
> >> the docs of QTextEdit contain the methods setTextFormat and textFormat
> >> in the section 'Member Function Documentation', but not in 'Public
> >> Functions' summary. I assume this method doesn't exist anymore and it's
> >> a doc bug. Right?
> > 
> > I can't see any doc bug. I guess you're talking about Qt3 here, because
> > Qt4 QTextEdit doesn't have this property at all (except maybe in the
> > Qt3support classes) and I see a public slot setTextFormat, as well as
> > the documented property and a getter function. Note public slots are
> > also public member functions, they are in a separate section because you
> > can connect signals to them, which is not possible with the other public
> > members.
> 
> Uuuuh-kay. So the assistant lists all members, Q3Support or not, in the
> same section.
> I was not aware of that. I'd say that is one giant bug

No, it doesn't do that for me here. On the main page for QTextEdit/Qt4 I
cannot see any reference to textFormat (neither property or setter). The
same for the list of all members. The only way to see Qt3Support members
of the QTextEdit class is by explicitly following the "Qt 3 support
members" link.

> because the doc tells you there is a method that doesn't exist.

The setTextFormat method still exists in Qt4, but it is part for the
Qt3-Compatibility API, which means two things:

a) You are discouraged from using it unless there's no Qt4-way of doing
what you want
b) You need to link your application against the qt3 support library -
AFAIK.

> Nonetheless, any idea how I can make the Qt4 text edit use plain text only?

Read the docs, the setText() functions documentation tells you how to do
it.

Andreas

-- 
 [ signature omitted ] 

Message 6 in thread

"Martin" <martin.umgeher@xxxxxxxxxxx> wrote in message
news:eqcgll$otl$1@xxxxxxxxxxxxxxxxxxxxx
> Uuuuh-kay. So the assistant lists all members, Q3Support or not, in the
> same section. I was not aware of that. I'd say that is one giant bug
> because the doc tells you there is a method that doesn't exist.

I'm running Qt4.2.2 on Windows.  If I launch QtAssistant and go to
the QTextEdit class, in the initial screen, there's no entry for
setTextFormat().  Same thing if I go to "list all members..."  It's
there if I choose the link for Qt3Support members.  So I don't
think it's a doc bug.

As to the Intellisense, it doesn't report this either but then there's
no setText() function in QTextEdit.  With some classes, like QLabel
typing label->setText   causes intellisense to fill it in with
setTextFormat.
This is pretty annoying actually but it may be an intellisense bug.  The
setText() function is not listed in the drop down list.

> Nonetheless, any idea how I can make the Qt4 text edit use plain text
only?
QTextEdit::setPlainText() maybe?

--
 [ signature omitted ] 

Message 7 in thread

Duane Hebert wrote:
> "Martin" <martin.umgeher@xxxxxxxxxxx> wrote in message
> news:eqcgll$otl$1@xxxxxxxxxxxxxxxxxxxxx
>> Uuuuh-kay. So the assistant lists all members, Q3Support or not, in the
>> same section. I was not aware of that. I'd say that is one giant bug
>> because the doc tells you there is a method that doesn't exist.
> 
> I'm running Qt4.2.2 on Windows.  If I launch QtAssistant and go to
> the QTextEdit class, in the initial screen, there's no entry for
> setTextFormat().  Same thing if I go to "list all members..."  It's
> there if I choose the link for Qt3Support members.  So I don't
> think it's a doc bug.

Interesting. I got both methods in the QTextEdit doc (as mentioned
before not in the summary section on top of the doc page, but down where
the 'detailed' descriptions are), and so does my colleague (we both use
4.2.2).

> As to the Intellisense, it doesn't report this either but then there's
> no setText() function in QTextEdit.  With some classes, like QLabel
> typing label->setText   causes intellisense to fill it in with
> setTextFormat.
> This is pretty annoying actually but it may be an intellisense bug.  The
> setText() function is not listed in the drop down list.
> 
>> Nonetheless, any idea how I can make the Qt4 text edit use plain text
> only?
> QTextEdit::setPlainText() maybe?
> 

Should have made myself clearer, once again :) I now how to set plain
text to the widget, and how to get it from the widget, but unfortunately
QDataWidgetMapper/QItemDelegate do not know that. When e.g. I use a
QTextEdit with a data widget mapper, the HTML-encoded version of the
entered text is passed to the underlying model. So I would need to tell
the text edit "don't use HTML representation at all, not even
internally". My hope was that setTextFormat(Qt::PlainText) would do the
trick, but it's gone in Qt4.

Thanks anyway!
M

--
 [ signature omitted ] 

Message 8 in thread

"Martin" <martin.umgeher@xxxxxxxxxxx> wrote in message
news:eqcldg$64g$1@xxxxxxxxxxxxxxxxxxxxx
> Interesting. I got both methods in the QTextEdit doc (as mentioned
> before not in the summary section on top of the doc page, but down where
> the 'detailed' descriptions are), and so does my colleague (we both use
> 4.2.2).

Maybe you have the wrong version of QtAssistant still lurking about.
What version does it list in the about box?

> Should have made myself clearer, once again :) I now how to set plain
> text to the widget, and how to get it from the widget, but unfortunately
> QDataWidgetMapper/QItemDelegate do not know that. When e.g. I use a
> QTextEdit with a data widget mapper, the HTML-encoded version of the
> entered text is passed to the underlying model. So I would need to tell
> the text edit "don't use HTML representation at all, not even
> internally". My hope was that setTextFormat(Qt::PlainText) would do the
> trick, but it's gone in Qt4.

Maybe this is what you want:

acceptRichText : bool
This property holds whether the text edit accepts rich text insertions by
the user.

When this propery is set to false text edit will accept only plain text
input from the user. For example through clipboard or drag and drop.

This property's default is true.

This property was introduced in Qt 4.1.

Access functions:

  a.. bool acceptRichText () const
  b.. void setAcceptRichText ( bool accept )


--
 [ signature omitted ] 

Message 9 in thread

Duane Hebert wrote:
> "Martin" <martin.umgeher@xxxxxxxxxxx> wrote in message
> news:eqcldg$64g$1@xxxxxxxxxxxxxxxxxxxxx
>> Interesting. I got both methods in the QTextEdit doc (as mentioned
>> before not in the summary section on top of the doc page, but down where
>> the 'detailed' descriptions are), and so does my colleague (we both use
>> 4.2.2).
> 
> Maybe you have the wrong version of QtAssistant still lurking about.
> What version does it list in the about box?

Nope, definately 4.2.2. If you text-search the QTextEdit docs page for
setTextFormat, you'll probably find it as well.


>> Should have made myself clearer, once again :) I now how to set plain
>> text to the widget, and how to get it from the widget, but unfortunately
>> QDataWidgetMapper/QItemDelegate do not know that. When e.g. I use a
>> QTextEdit with a data widget mapper, the HTML-encoded version of the
>> entered text is passed to the underlying model. So I would need to tell
>> the text edit "don't use HTML representation at all, not even
>> internally". My hope was that setTextFormat(Qt::PlainText) would do the
>> trick, but it's gone in Qt4.
> 
> Maybe this is what you want:
> 
> acceptRichText : bool
> This property holds whether the text edit accepts rich text insertions by
> the user.

Already tried this one, but it doesn't change what the QTextEdit stores
internally, only what it accepts as input.

M

--
 [ signature omitted ] 

Message 10 in thread

"Martin" <martin.umgeher@xxxxxxxxxxx> wrote in message
news:eqcmd4$9es$1@xxxxxxxxxxxxxxxxxxxxx

> Nope, definately 4.2.2. If you text-search the QTextEdit docs page for
> setTextFormat, you'll probably find it as well.

It does show up in a text search.  It seems that the main
doc and the qtsupport doc are in the same html file.  I haven't
checked this though.  I ususally look at the initial list
and then if I don't see what I'm looking for, I go to the
"show all functions" link.  I see what you mean though.

> > Maybe this is what you want:
> >
> > acceptRichText : bool
> > This property holds whether the text edit accepts rich text insertions
by
> > the user.
>
> Already tried this one, but it doesn't change what the QTextEdit stores
> internally, only what it accepts as input.

Ok.  I guess you need to contact support@xxxxxxxxxxxxx then.

--
 [ signature omitted ] 

Message 11 in thread

On 07.02.07 10:24:22, Duane Hebert wrote:
> "Martin" <martin.umgeher@xxxxxxxxxxx> wrote in message
> news:eqcmd4$9es$1@xxxxxxxxxxxxxxxxxxxxx
> 
> > Nope, definately 4.2.2. If you text-search the QTextEdit docs page for
> > setTextFormat, you'll probably find it as well.
> 
> It does show up in a text search.  It seems that the main
> doc and the qtsupport doc are in the same html file.

No they're not. The qt3 stuff is solely in qtextedit-qt3.html, but this
occurrence is in qtextedit.html. A small doc-bug it seems.

Andreas

-- 
 [ signature omitted ] 

Message 12 in thread

On 07.02.07 08:55:58, Duane Hebert wrote:
> 
> "Martin" <martin.umgeher@xxxxxxxxxxx> wrote in message
> news:eqcldg$64g$1@xxxxxxxxxxxxxxxxxxxxx
> > Interesting. I got both methods in the QTextEdit doc (as mentioned
> > before not in the summary section on top of the doc page, but down where
> > the 'detailed' descriptions are), and so does my colleague (we both use
> > 4.2.2).
> 
> Maybe you have the wrong version of QtAssistant still lurking about.
> What version does it list in the about box?

He's right actually. Qt4 docs have the setTextFormat function in the
qtextedit.html file, just search for the function in the file or jump to
the details of setPointSize and scroll a bit down.

> > Should have made myself clearer, once again :) I now how to set plain
> > text to the widget, and how to get it from the widget, but unfortunately
> > QDataWidgetMapper/QItemDelegate do not know that. When e.g. I use a
> > QTextEdit with a data widget mapper, the HTML-encoded version of the
> > entered text is passed to the underlying model. So I would need to tell
> > the text edit "don't use HTML representation at all, not even
> > internally". My hope was that setTextFormat(Qt::PlainText) would do the
> > trick, but it's gone in Qt4.
 
Once again: The setTextFormat function is _not_ gone in Qt4, it just
moved to the Qt3 support libraries which you have to explicitly link to
if you want to use them.

> acceptRichText : bool
> This property holds whether the text edit accepts rich text insertions by
> the user.

Judging from the code it won't help, the setText function bases the
decision wether its using setHtml or setPlainText solely on the
Qt::mightBeRichText which in turn looks for words enclosed in <> if I
understand the code right.

It seems there's no way but subclassing QTextEdit to force a plaintext
widget, which shouldn't be much of a problem.

Andreas

-- 
 [ signature omitted ] 

Message 13 in thread

"Andreas Pakulat" <apaku@xxxxxx> wrote in message
news:20070207142714.GA23543@xxxxxxxxxxxxxxxxxxxxxxxxxxxxxx

> He's right actually. Qt4 docs have the setTextFormat function in the
> qtextedit.html file, just search for the function in the file or jump to
> the details of setPointSize and scroll a bit down.

Yep.  I guess you could call that a doc bug then.

> It seems there's no way but subclassing QTextEdit to force a plaintext
> widget, which shouldn't be much of a problem.

Seems like Justin showed him how to do it.


--
 [ signature omitted ] 

Message 14 in thread

Martin wrote:
> Duane Hebert wrote:
>   
>> Should have made myself clearer, once again :) I now how to set plain
>> text to the widget, and how to get it from the widget, but unfortunately
>> QDataWidgetMapper/QItemDelegate do not know that. When e.g. I use a
>> QTextEdit with a data widget mapper, the HTML-encoded version of the
>> entered text is passed to the underlying model. So I would need to tell
>> the text edit "don't use HTML representation at all, not even
>> internally". My hope was that setTextFormat(Qt::PlainText) would do the
>> trick, but it's gone in Qt4.
>>
>>     


QDataWidgetMapper is powered by a magic USER flag in the Q_PROPERTY 
declarations of a widget.  I wish there was an API to override the 
property used, but this might work.

class MyTextEdit : public QTextEdit
{
  Q_OBJECT
  Q_PROPERTY(QString plainText READ toPlainText WRITE setPlainText 
STORED false NOTIFY textChanged USER true)

  MyTextEdit(QWidget* parent=0)

};


The default for QTextEdit is:
Q_PROPERTY(QString html READ toHtml WRITE setHtml NOTIFY textChanged 
USER true)

begin:vcard
begin:vcard
fn:Justin Noel
n:Noel;Justin
org:ICS;Engineering
adr:;;54B Middlesex Trpk;Bedford;MA;01730;USA
email;internet:justin@xxxxxxx
title:Sr. Consulting Engineer / Certified Qt Instructor
tel;work:(617) 621-0060
url:http://www.ics.com
version:2.1
end:vcard


Message 15 in thread

Justin Noel wrote:
> Martin wrote:
>> Duane Hebert wrote:
>>  
>>> Should have made myself clearer, once again :) I now how to set plain
>>> text to the widget, and how to get it from the widget, but unfortunately
>>> QDataWidgetMapper/QItemDelegate do not know that. When e.g. I use a
>>> QTextEdit with a data widget mapper, the HTML-encoded version of the
>>> entered text is passed to the underlying model. So I would need to tell
>>> the text edit "don't use HTML representation at all, not even
>>> internally". My hope was that setTextFormat(Qt::PlainText) would do the
>>> trick, but it's gone in Qt4.
>>>
>>>     
> 
> 
> QDataWidgetMapper is powered by a magic USER flag in the Q_PROPERTY
> declarations of a widget.  I wish there was an API to override the
> property used, but this might work.
> 
> class MyTextEdit : public QTextEdit
> {
>  Q_OBJECT
>  Q_PROPERTY(QString plainText READ toPlainText WRITE setPlainText STORED
> false NOTIFY textChanged USER true)
> 
>  MyTextEdit(QWidget* parent=0)
> 
> };
> 
> 
> The default for QTextEdit is:
> Q_PROPERTY(QString html READ toHtml WRITE setHtml NOTIFY textChanged
> USER true)
> 

I've stumbled across the read/write properties inside QItemDelegate
during debugging, but wasn't aware that it is sooo easy to override
them. Thanks a lot, that instantly worked!

M


P.S.: I was looking for a built-in way without creating a custom class
because the Qt3-to-Qt4 porting guide said something about using "the new
QTextEdit API" as a replacement for the Qt3 method setTextFormat.
Apparently, there is no way to do that with the new API, but what the
heck :)

--
 [ signature omitted ] 

Pages: Prev | 1 | 2 | Next