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

Qt-interest Archive, January 2008
how to select line edit text box on single mouse click


Message 1 in thread

  
hi every one
i m sanjeev
i m working on qt3 version and i have a query so can some one help me in this problem ??
my problem is : -
"i have a QLineedit text box and on a singel mouse click on the text box the cursor moves to the first position bt i want whole text message should be selected on a single mouse click just like on the address bar of the explorer as we click on the address bar the whole text is selected and on the same way i want this functioning in qlineedit"

plz help me in solving my problem
i will b very thank full
sanjeev

Message 2 in thread

Hello Sanjeev,

you could create your own subclass of QLineEdit, reimplement
focusInEvent(), and call selectAll() in there.

Cheers,
Peter

sanjeev kumar wrote:
> hi every one
> i m sanjeev
> i m working on qt3 version and i have a query so can some one 
> help me in this problem ??
> my problem is : -
> "i have a QLineedit text box and on a singel mouse click on 
> the text box the cursor moves to the first position bt i want 
> whole text message should be selected on a single mouse click 
> just like on the address bar of the explorer as we click on 
> the address bar the whole text is selected and on the same 
> way i want this functioning in qlineedit"
> 
> plz help me in solving my problem
> i will b very thank full
> sanjeev 

--
 [ signature omitted ] 

Message 3 in thread

On Wed, January 16, 2008 18:37, sanjeev kumar wrote:
> hi every one i m sanjeev i m working on qt3 version and i have a query so can
> some one help me in this problem ?? my problem is : - "i have a QLineedit
> text box and on a singel mouse click on the text box the cursor moves to
> the first position bt i want whole text message should be selected on a
> single mouse click just like on the address bar of the explorer as we click
> on the address bar the whole text is selected and on the same way i want
> this functioning in qlineedit"
>
> plz help me in solving my problem i will b very thank full sanjeev
I think you will have to sub-class from QLineEdit and add a call to
QLineEdit::selectAll() within the overloaded mousePressEvent().

http://doc.trolltech.com/3.3/qwidget.html#mousePressEvent

HTH, René
-- 
 [ signature omitted ] 

Message 4 in thread

On Jan 16, 2008 2:13 PM, R. Reucher <rene.reucher@xxxxxxxxxxxxx> wrote:

> On Wed, January 16, 2008 18:37, sanjeev kumar wrote:
> > hi every one i m sanjeev i m working on qt3 version and i have a query
> so can
> > some one help me in this problem ?? my problem is : - "i have a
> QLineedit
> > text box and on a singel mouse click on the text box the cursor moves to
> > the first position bt i want whole text message should be selected on a
> > single mouse click just like on the address bar of the explorer as we
> click
> > on the address bar the whole text is selected and on the same way i want
> > this functioning in qlineedit"
> >
> > plz help me in solving my problem i will b very thank full sanjeev
> I think you will have to sub-class from QLineEdit and add a call to
> QLineEdit::selectAll() within the overloaded mousePressEvent().
>

Actually, you don't want to do this, or if you do, you need to check if the
line edit already has focus. Otherwise, every time the user clicks all of
the text will be selected, so they won't be able to use the mouse to move
the cursor or select a subset of the text. Not that I've done this
before....

Using the focusInEvent() is probably better, but make sure you test it
fairly thoroughly to make sure you don't miss an annoying side effect.

Tom

Message 5 in thread

On Wed, January 16, 2008 20:28, Tom Panning wrote:
> On Jan 16, 2008 2:13 PM, R. Reucher <rene.reucher@xxxxxxxxxxxxx> wrote:
>> I think you will have to sub-class from QLineEdit and add a call to
>> QLineEdit::selectAll() within the overloaded mousePressEvent().
>
> Actually, you don't want to do this, or if you do, you need to check if the
> line edit already has focus. Otherwise, every time the user clicks all of
> the text will be selected, so they won't be able to use the mouse to move
> the cursor or select a subset of the text. Not that I've done this
> before....
>
> Using the focusInEvent() is probably better, but make sure you test it
> fairly thoroughly to make sure you don't miss an annoying side effect.
Either way, you will have to include some more "logic", I agree...

René
-- 
 [ signature omitted ] 

Message 6 in thread

Simple... Of course its always simple when your only going to write
pseudo code :-) You don't have to subclass at all...

 

In your dialog/mainwindown class, after the construction of the line
edit, add a event filter to it....

 

MyWIndow::MyWindow(....)

{

            Construct all children...

            

            lineEdit->installEventFilter( this );

}

 

Then create an event filter method on the objet

 

Bool MyWindow::eventFilter( QObject * obj, QEvent * event )

{

            If ( event->type() == QEvent::MouseButtonPress &&
qobject_cast< QLineEdit * >( obj ) ) // note I don't have my qt 3 docs
anymore, you'll have to look up the enum on your own

            {

                        QLineEdit * le = qobject_cast< QLineEdit * >(
obj );

                        le->selectAll(); // I forget the qt 3 call here

                        return true;

            }

            Return BaseClass::eventFilter( obj, event );

}

 

 

Good luck.. and may the force be with you

 

Scott

 

________________________________

From: sanjeev kumar [mailto:sanjeev_iic@xxxxxxxxxxxxxx] 
Sent: Wednesday, January 16, 2008 9:37 AM
To: qt-interest@xxxxxxxxxxxxx
Subject: how to select line edit text box on single mouse click

 

  
hi every one
i m sanjeev
i m working on qt3 version and i have a query so can some one help me in
this problem ??
my problem is : -
"i have a QLineedit text box and on a singel mouse click on the text box
the cursor moves to the first position bt i want whole text message
should be selected on a single mouse click just like on the address bar
of the explorer as we click on the address bar the whole text is
selected and on the same way i want this functioning in qlineedit"

plz help me in solving my problem
i will b very thank full
sanjeev 

 

Jeevan Sathi
<http://adworks.rediff.com/cgi-bin/AdWorks/click.cgi/www.rediff.com/sign
ature-home.htm/1050715198@Middle5/2031830_2024620/2031710/1?PARTNER=3&OA
S_QUERY=null> 

 


Message 7 in thread

hi
plz suggest how i should connect the QLineEdit class object to mousePressEvent()  
because there is no such signal clicked() as in case of QPushButton
so tell me how should i register the QLineEdit object with the mousePressEvent()

thank you
sanjeev

On Thu, 17 Jan 2008 RReucher wrote :
>On Wed, January 16, 2008 20:28, Tom Panning wrote:
> > On Jan 16, 2008 2:13 PM, R. Reucher <rene.reucher@xxxxxxxxxxxxx> wrote:
> >> I think you will have to sub-class from QLineEdit and add a call to
> >> QLineEdit::selectAll() within the overloaded mousePressEvent().
> >
> > Actually, you don't want to do this, or if you do, you need to check if the
> > line edit already has focus. Otherwise, every time the user clicks all of
> > the text will be selected, so they won't be able to use the mouse to move
> > the cursor or select a subset of the text. Not that I've done this
> > before....
> >
> > Using the focusInEvent() is probably better, but make sure you test it
> > fairly thoroughly to make sure you don't miss an annoying side effect.
>Either way, you will have to include some more "logic", I agree...
>
>René
>--
>René Reucher
>Tel: +49 160 7115802
>FAX: +49 6359 205423
>rene.reucher@xxxxxxxxxxxxx
>http://www.batcom-it.net/
>
>--
>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/
>

Message 8 in thread

On Fri, January 18, 2008 07:53, sanjeev kumar wrote:
> hi plz suggest how i should connect the QLineEdit class object to
> mousePressEvent() because there is no such signal clicked() as in case of
> QPushButton
> so tell me how should i register the QLineEdit object with the
> mousePressEvent()
Just as I said... you have to sub-class from QLineEdit and overload the
protected virtual function mousePressEvent(QMouseEvent *), which is
inherited from QWidget:

http://doc.trolltech.com/3.3/qwidget.html#mousePressEvent

If you don't know HOW to accomplish that, don't do it :) right now and read
more on implementing you're own event-handlers here:

http://doc.trolltech.com/3.3/eventsandfilters.html

Anyway, if you do, you'll have to take care about what has been said before.

René
-- 
 [ signature omitted ] 

Message 9 in thread

BTW, and a bit OT... I don't think that this is a good idea anyway, because
it's not a nice GUI behavior to select all text on the first (single) click
into a QLineEdit. It does that on a double-click, which should be
sufficient.

Do you really think that what M$ IE does should be considered a "reference
GUI behavior"? I would personally not follow their mistakes...

I could think of more useful reasons to implement your own mousePressEvent()
(or whatever solution might be better to solve this) for a QLineEdit, i. e.
clearing the entry for a search pattern on the first click, like many
web-sites do it.

But this is just my personal opinion and of course, it's a matter of taste.

Have fun, René
-- 
 [ signature omitted ]