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

Qt-interest Archive, January 2007
controlling QTextEdit (Qt 4.2.0)


Message 1 in thread

Hi there,

I would like to assess the way QTextEdit accepts user's text input. 
Precisely my goal is to make a Hexadecimal editor, that is the user can only 
enter the letter 0-9 A-F, 2 chars separated by spaces, and so on...

I have already a way to do that but it is very ugly (by catching the signal 
textChanged and correcting the text to verify the hex format). I am 
wondering if there is a simpler way using Qt dedicated methods (maybe with 
QRegExp???) I am looking over the documentation but so far didn't find what 
I want.

Thanks for your help.

Cheers,
Nil

_________________________________________________________________
Personnalisez votre Messenger avec Live.com 
http://www.windowslive.fr/livecom/

--
 [ signature omitted ] 

Message 2 in thread

Take a look at the manual, about "QRegExpValidator".

Regards,
Thomas

nilitonilito nilitonilito schrieb:
> Hi there,
> 
> I would like to assess the way QTextEdit accepts user's text input. 
> Precisely my goal is to make a Hexadecimal editor, that is the user can 
> only enter the letter 0-9 A-F, 2 chars separated by spaces, and so on...
> 
> I have already a way to do that but it is very ugly (by catching the 
> signal textChanged and correcting the text to verify the hex format). I 
> am wondering if there is a simpler way using Qt dedicated methods (maybe 
> with QRegExp???) I am looking over the documentation but so far didn't 
> find what I want.
> 
> Thanks for your help.
> 
> Cheers,
> Nil
> 
> _________________________________________________________________
> Personnalisez votre Messenger avec Live.com 
> http://www.windowslive.fr/livecom/
> 
> -- 
> To unsubscribe - send a mail to qt-interest-request@xxxxxxxxxxxxx with 
> "unsubscribe" in the subject or the body.
> List archive and information: http://lists.trolltech.com/qt-interest/
> 
> 

--
 [ signature omitted ] 

Message 3 in thread

Hi Thomas,

thanks for your fast answer. I did take a look at QRegExpValidator (although 
not completly) but it seems that it is only applyable for QLineEdit not 
QTextEdit, I am right?

Nil


>From: Thomas Dähling <t.daehling@xxxxxxxxxxxxxx>
>To: qt-interest@xxxxxxxxxxxxx
>Subject: Re: controlling QTextEdit (Qt 4.2.0)
>Date: Sun, 21 Jan 2007 13:18:44 +0100
>
>Take a look at the manual, about "QRegExpValidator".
>
>Regards,
>Thomas
>
>nilitonilito nilitonilito schrieb:
>>Hi there,
>>
>>I would like to assess the way QTextEdit accepts user's text input. 
>>Precisely my goal is to make a Hexadecimal editor, that is the user can 
>>only enter the letter 0-9 A-F, 2 chars separated by spaces, and so on...
>>
>>I have already a way to do that but it is very ugly (by catching the 
>>signal textChanged and correcting the text to verify the hex format). I am 
>>wondering if there is a simpler way using Qt dedicated methods (maybe with 
>>QRegExp???) I am looking over the documentation but so far didn't find 
>>what I want.
>>
>>Thanks for your help.
>>
>>Cheers,
>>Nil
>>
>>_________________________________________________________________
>>Personnalisez votre Messenger avec Live.com 
>>http://www.windowslive.fr/livecom/
>>
>>--
>>To unsubscribe - send a mail to qt-interest-request@xxxxxxxxxxxxx with 
>>"unsubscribe" in the subject or the body.
>>List archive and information: http://lists.trolltech.com/qt-interest/
>>
>>
>
>--
>To unsubscribe - send a mail to qt-interest-request@xxxxxxxxxxxxx with 
>"unsubscribe" in the subject or the body.
>List archive and information: http://lists.trolltech.com/qt-interest/
>

_________________________________________________________________
Ten :  Messenger en illimité sur votre mobile !  
http://mobile.live.fr/messenger/ten/

--
 [ signature omitted ] 

Message 4 in thread

Well, there is of course the way to catch the signal TextChanged and undo 
the input text that led to an  Invalid state from QRegExpValidate, but is 
there some more direct way like in QLineEdit?

Nil

>Hi Thomas,
>
>thanks for your fast answer. I did take a look at QRegExpValidator 
>(although not completly) but it seems that it is only applyable for 
>QLineEdit not QTextEdit, I am right?
>
>Nil
>
>
>>From: Thomas Dähling <t.daehling@xxxxxxxxxxxxxx>
>>To: qt-interest@xxxxxxxxxxxxx
>>Subject: Re: controlling QTextEdit (Qt 4.2.0)
>>Date: Sun, 21 Jan 2007 13:18:44 +0100
>>
>>Take a look at the manual, about "QRegExpValidator".
>>
>>Regards,
>>Thomas
>>
>>nilitonilito nilitonilito schrieb:
>>>Hi there,
>>>
>>>I would like to assess the way QTextEdit accepts user's text input. 
>>>Precisely my goal is to make a Hexadecimal editor, that is the user can 
>>>only enter the letter 0-9 A-F, 2 chars separated by spaces, and so on...
>>>
>>>I have already a way to do that but it is very ugly (by catching the 
>>>signal textChanged and correcting the text to verify the hex format). I 
>>>am wondering if there is a simpler way using Qt dedicated methods (maybe 
>>>with QRegExp???) I am looking over the documentation but so far didn't 
>>>find what I want.
>>>
>>>Thanks for your help.
>>>
>>>Cheers,
>>>Nil
>>>
>>>_________________________________________________________________
>>>Personnalisez votre Messenger avec Live.com 
>>>http://www.windowslive.fr/livecom/
>>>
>>>--
>>>To unsubscribe - send a mail to qt-interest-request@xxxxxxxxxxxxx with 
>>>"unsubscribe" in the subject or the body.
>>>List archive and information: http://lists.trolltech.com/qt-interest/
>>>
>>>
>>
>>--
>>To unsubscribe - send a mail to qt-interest-request@xxxxxxxxxxxxx with 
>>"unsubscribe" in the subject or the body.
>>List archive and information: http://lists.trolltech.com/qt-interest/
>>
>
>_________________________________________________________________
>Ten :  Messenger en illimité sur votre mobile !  
>http://mobile.live.fr/messenger/ten/
>
>--
>To unsubscribe - send a mail to qt-interest-request@xxxxxxxxxxxxx with 
>"unsubscribe" in the subject or the body.
>List archive and information: http://lists.trolltech.com/qt-interest/
>

_________________________________________________________________
Gagnez des pc Windows Vista avec Live.com http://www.image-addict.fr/

--
 [ signature omitted ] 

Message 5 in thread

Nil,

My reading of the docs: QRegExpValidator can check any string.
QTextEdit allows you to convert "toPlainText()" which returns a string.  As 
long as you can arrange to catch your string at the right time I think you've 
possibly got what you need.

A


On Sunday 21 January 2007 12:48, nilitonilito nilitonilito wrote:

> >Hi Thomas,
> >
> >thanks for your fast answer. I did take a look at QRegExpValidator
> >(although not completly) but it seems that it is only applyable for
> >QLineEdit not QTextEdit, I am right?
> >
> >Nil

--
 [ signature omitted ] 

Message 6 in thread

"amit" <pom2@xxxxxxxxxxxxxxxx> wrote in message
news:200701211301.36824.pom2@xxxxxxxxxxxxxxxxxxx
> Nil,
>
> My reading of the docs: QRegExpValidator can check any string.
> QTextEdit allows you to convert "toPlainText()" which returns a string.
As
> long as you can arrange to catch your string at the right time I think
you've
> possibly got what you need.

Well you can use QValidator without attaching it to
a line edit:

QIntValidator doh(this);
QString input("42");
int pos = input.size() - 1;  // the last value
if(doh.validate(input,pos) != QValidator::Acceptable) {

    input[pos] = "";  // or something
}

But to do this, you would need to check the string using
asPlainText() on each keypress and if it's invalid, strip
the last char and call setPlainText().  Doesn't sound very
efficient.  You may be able to do something with QTextCursor though.

--
 [ signature omitted ] 

Message 7 in thread

Hi there,

I would like to formulate the following QRegExp :

All hexadecimal number of 2 digits except F7.

I know how to formulate all hexadecimal with 2 digit :

([A-F]|\\d){1,2}

I know how to formulate not F7 :

(?!F7)

but I don't know how to formulate their conjonction?

Thanks for your help
Cheers,
Nil

_________________________________________________________________
Découvrez le Blog heroic Fantaisy d'Eragon! 
http://eragon-heroic-fantasy.spaces.live.com/

--
 [ signature omitted ] 

Message 8 in thread

Hello Nil,

I am not an expert on regular expressions, so I would suggest this naive one 
that I tested with Regex tester part of the examples programs provided with 
Qt. It looks like
([A-E]|\\d)([A-F]|\\d)|F([A-F]|[0-6]|[8-9]) (in C++) may work in your case.
It matches (hopefully) all hexadecimal with exactly 2 digits except for F7. 
Capture#1 gives the first digit and Capture#2 gives the second digit.

It is now nightime in Europe, and I know that Europeans love this kind of 
stuff, so I am sure you'll get perhaps a more "effective" regular expression 
tomorrow.

You can also try the Regex tester given with Qt example programs, I am sure 
they package it with Qt4.

Christopher

>From: "nilitonilito nilitonilito" <nilitonilito@xxxxxxxxxxx>
>To: qt-interest@xxxxxxxxxxxxx
>Subject: [Qt 4.2.0] QRegExp
>Date: Mon, 22 Jan 2007 20:06:10 +0100
>
>Hi there,
>
>I would like to formulate the following QRegExp :
>
>All hexadecimal number of 2 digits except F7.
>
>I know how to formulate all hexadecimal with 2 digit :
>
>([A-F]|\\d){1,2}
>
>I know how to formulate not F7 :
>
>(?!F7)
>
>but I don't know how to formulate their conjonction?
>
>Thanks for your help
>Cheers,
>Nil
>
>_________________________________________________________________
>Découvrez le Blog heroic Fantaisy d'Eragon! 
>http://eragon-heroic-fantasy.spaces.live.com/
>
>--
>To unsubscribe - send a mail to qt-interest-request@xxxxxxxxxxxxx with 
>"unsubscribe" in the subject or the body.
>List archive and information: http://lists.trolltech.com/qt-interest/
>

_________________________________________________________________
Achetez ce que vous voulez, quand vous voulez sur Sympatico / MSN Magasiner 
http://magasiner.sympatico.msn.ca/content/shp/?ctId=101,ptnrid=176,ptnrdata=081805

--
 [ signature omitted ] 

Message 9 in thread

Hi,

nilitonilito nilitonilito wrote:
> All hexadecimal number of 2 digits except F7.
> 
> I know how to formulate all hexadecimal with 2 digit :
> 
> ([A-F]|\\d){1,2}

Isn't that matching either one or two characters? Maybe ([A-F]|\\d){2,2}

> I know how to formulate not F7 :
> 
> (?!F7)
> 
> but I don't know how to formulate their conjonction?

Just stick them together:

(?!F7)([A-F]|\\d){2,2}

Tim

--
 [ signature omitted ] 

Message 10 in thread

Hi Tim,

The regexp I need is : 1 or 2 hex except f7

(?!F7)([A-F]|\\d){1,2}

is working fine.

Many thanks
Nil

and
>From: Tim Dewhirst <tim@xxxxxxxxxxxxx>
>To: nilitonilito nilitonilito <nilitonilito@xxxxxxxxxxx>
>CC: qt-interest@xxxxxxxxxxxxx
>Subject: Re: [Qt 4.2.0] QRegExp
>Date: Mon, 22 Jan 2007 22:31:04 +0000
>
>Hi,
>
>nilitonilito nilitonilito wrote:
>>All hexadecimal number of 2 digits except F7.
>>
>>I know how to formulate all hexadecimal with 2 digit :
>>
>>([A-F]|\\d){1,2}
>
>Isn't that matching either one or two characters? Maybe ([A-F]|\\d){2,2}
>
>>I know how to formulate not F7 :
>>
>>(?!F7)
>>
>>but I don't know how to formulate their conjonction?
>
>Just stick them together:
>
>(?!F7)([A-F]|\\d){2,2}
>
>Tim
>
>--
>To unsubscribe - send a mail to qt-interest-request@xxxxxxxxxxxxx with 
>"unsubscribe" in the subject or the body.
>List archive and information: http://lists.trolltech.com/qt-interest/
>

_________________________________________________________________
Découvrez le Blog heroic Fantaisy d'Eragon! 
http://eragon-heroic-fantasy.spaces.live.com/

--
 [ signature omitted ] 

Message 11 in thread

Well, I've found excatly what I need, it is QValidator, but it seems that it 
is for QLineEdit, not for QTextEdit, is there any way to have QValidator on 
QTextEdit?

Thanks
Nil


>From: "nilitonilito nilitonilito" <nilitonilito@xxxxxxxxxxx>
>To: qt-interest@xxxxxxxxxxxxx
>Subject: controlling QTextEdit (Qt 4.2.0)
>Date: Sun, 21 Jan 2007 13:02:22 +0100
>
>Hi there,
>
>I would like to assess the way QTextEdit accepts user's text input. 
>Precisely my goal is to make a Hexadecimal editor, that is the user can 
>only enter the letter 0-9 A-F, 2 chars separated by spaces, and so on...
>
>I have already a way to do that but it is very ugly (by catching the signal 
>textChanged and correcting the text to verify the hex format). I am 
>wondering if there is a simpler way using Qt dedicated methods (maybe with 
>QRegExp???) I am looking over the documentation but so far didn't find what 
>I want.
>
>Thanks for your help.
>
>Cheers,
>Nil
>
>_________________________________________________________________
>Personnalisez votre Messenger avec Live.com 
>http://www.windowslive.fr/livecom/
>
>--
>To unsubscribe - send a mail to qt-interest-request@xxxxxxxxxxxxx with 
>"unsubscribe" in the subject or the body.
>List archive and information: http://lists.trolltech.com/qt-interest/
>

_________________________________________________________________
Découvrez le Blog heroic Fantaisy d'Eragon! 
http://eragon-heroic-fantasy.spaces.live.com/

--
 [ signature omitted ]