user63898
user63898

Reputation: 30885

In QTextEdit how can you detect when user inserts the cursor into the text area only once?

I have QTextEdit with Text init like :

write something here.... 

Now I'd like that the start signal that triggered only once so when the user enter its mouse cursor into the text area the string will removed and the text area will be ready to write. I need it to be triggers only once when the widget is up.
I only found the :

connect( textEdit, SIGNAL( cursorPositionChanged( int para, int pos ) ), 
         <.....>,  SLOT( Position ( int para, int pos ) ) );

but I don't know how to trigger it once , or is it the right way for this.

Upvotes: 0

Views: 449

Answers (2)

TonyK
TonyK

Reputation: 17114

If your QTextEdit widget is only a single line, you might want to consider using a QLineEdit widget instead. Then you can call setPlaceholderText("write something here.... ") to get the effect you want. Click here for more info.

Upvotes: 1

Mat
Mat

Reputation: 206679

You could disconnect that connection in the Position slot. That way that slot will only be triggered once.

Another option is simply to keep a boolean in the object that receives the signal that indicates whether or not it should do something when the slot is called.

(You'll probably find yourself wanting to "rearm" that slot. Either call connect again, or reset that boolean, depending on what option you chose.)

Upvotes: 2

Related Questions