Results 1 to 15 of 15

Thread: MouseEvent on QTextEdit

  1. #1
    Join Date
    Mar 2006
    Location
    Hyderabad
    Posts
    69
    Thanks
    5
    Thanked 1 Time in 1 Post
    Qt products
    Qt3
    Platforms
    Unix/X11

    Default MouseEvent on QTextEdit

    Sir,
    I have a textedit which is the child widget of another parent. I have implemented the mouseDoubleClickEvent on the text edit and my requirement is that when I doubleclick on a line, I should get that entire line. Here is a part of my code:
    Qt Code:
    1. if( e->type() == QEvent::MouseButtonDblClick ) // Mouse Double clicked
    2. {
    3. int *para1,*para2,*index1,*index2;
    4. if( te->hasSelectedText() )
    5. {
    6. system("echo mouse clicked");
    7. te->getSelection(para1,index1,para2,index2,0);
    8. }
    9.  
    10. QString line=te->text(*para1);
    11. // print line in another widget for testing purpose
    12. //call to another function
    13. return true;
    14. }
    To copy to clipboard, switch view to plain text mode 
    Now, when I doubleclick the mouse, I could not see the output on console. And when I remove the if -condition inside, I could see the output on console.But the program is exiting itself by reporting "Bus error" on the console. Kindly help me in solving this problem.
    Thanks and regards,
    Sarma.

  2. #2
    Join Date
    Jan 2006
    Location
    Ukraine,Lviv
    Posts
    454
    Thanks
    9
    Thanked 27 Times in 27 Posts
    Qt products
    Qt3
    Platforms
    Unix/X11 Windows

    Default Re: MouseEvent on QTextEdit

    Its ok becouse when you catch your doubleclick text is not selected yet
    a life without programming is like an empty bottle

  3. #3
    Join Date
    Mar 2006
    Location
    Hyderabad
    Posts
    69
    Thanks
    5
    Thanked 1 Time in 1 Post
    Qt products
    Qt3
    Platforms
    Unix/X11

    Default Re: MouseEvent on QTextEdit

    hi,
    I understood something. Generally when we double click in a text edit, we see that word being selected which is not happening in my application. Hence the if-condition fails and no output is printed on the console. And when I remove the if-condition, exiting of the program by reporting "Bus error" occurs because of the 7th line.
    But that doesnot solve my problem . Can anyone help me in this regard?

  4. #4
    Join Date
    Mar 2006
    Location
    Hyderabad
    Posts
    69
    Thanks
    5
    Thanked 1 Time in 1 Post
    Qt products
    Qt3
    Platforms
    Unix/X11

    Default Re: MouseEvent on QTextEdit

    Dear Wysota sir,

    You said that we can get the line by calculating the cursor positions.If it is so, please let me know the steps that I have to write to get the application working.It got struck up since morning just because of this

    Regards,
    Sarma.

  5. #5
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    5,372
    Thanks
    28
    Thanked 976 Times in 912 Posts
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11 Windows

    Default Re: MouseEvent on QTextEdit

    Quote Originally Posted by Sarma
    Qt Code:
    1. int *para1,*para2,*index1,*index2;
    2. if( te->hasSelectedText() )
    3. {
    4. system("echo mouse clicked");
    5. te->getSelection(para1,index1,para2,index2,0);
    6. }
    To copy to clipboard, switch view to plain text mode 
    This should be:
    Qt Code:
    1. int para1, para2, index1, index2;
    2. if( te->hasSelectedText() )
    3. {
    4. system("echo mouse clicked");
    5. te->getSelection( &para1, &index1, &para2, &index2, 0 );
    6. }
    To copy to clipboard, switch view to plain text mode 
    Otherwise QTextEdit::getSelection() will overwrite some random memory location which will cause a segmentation fault.

  6. #6
    Join Date
    Mar 2006
    Location
    Hyderabad
    Posts
    69
    Thanks
    5
    Thanked 1 Time in 1 Post
    Qt products
    Qt3
    Platforms
    Unix/X11

    Default Re: MouseEvent on QTextEdit

    hi jacek,
    well, thats not the solution because when there is no text selected, u are not supposed to use getselection() method whatever may be the usage of its parameters.
    I have found the solution to maximum extent but I couldnot make it till the end. The have changed the code like this:
    Qt Code:
    1. int para= te->paragraphAt(QCursor::pos()); // te is the textEdit object
    2. QString line=te->text(para);
    To copy to clipboard, switch view to plain text mode 

    But the thing is when I load some file into textedit, the cursor will be at the end of the textedit. So, at any time, the first line returns the last para number.
    Now, Please tell me how to move the cursor to the place where Iam clicking the mouse.

    Thanks and regards,
    Sarma.

  7. #7
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    5,372
    Thanks
    28
    Thanked 976 Times in 912 Posts
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11 Windows

    Default Re: MouseEvent on QTextEdit

    Quote Originally Posted by Sarma
    Now, Please tell me how to move the cursor to the place where Iam clicking the mouse.
    Shouldn't this happen automatically?

  8. #8
    Join Date
    Mar 2006
    Location
    Hyderabad
    Posts
    69
    Thanks
    5
    Thanked 1 Time in 1 Post
    Qt products
    Qt3
    Platforms
    Unix/X11

    Default Re: MouseEvent on QTextEdit

    jacek,
    Please don't pose those kind of questions, my dear. kindly tell the answer.

  9. #9
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    5,372
    Thanks
    28
    Thanked 976 Times in 912 Posts
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11 Windows

    Default Re: MouseEvent on QTextEdit

    Quote Originally Posted by Sarma
    Please don't pose those kind of questions, my dear. kindly tell the answer.
    Why? Is all you want is a fish?

    QTextEdit provides such functionality out of the box. Why do you want to implement something that is already implemented?

  10. #10
    Join Date
    Mar 2006
    Location
    Hyderabad
    Posts
    69
    Thanks
    5
    Thanked 1 Time in 1 Post
    Qt products
    Qt3
    Platforms
    Unix/X11

    Exclamation Re: MouseEvent on QTextEdit

    hi,
    Yes, QTextEdit has got such kind of functionality. But I don't know why it is not happenning in my application. Iam showing you a part of my code:
    Qt Code:
    1. if( e->type() == QEvent::MouseButtonDblClick )
    2. {
    3. int para1= te->paragraphAt(QCursor::pos());
    4. QString line=te->text(para1);
    5. return true;
    6. }
    To copy to clipboard, switch view to plain text mode 

    Now, when mouse is DoubleClicked, para1 is holding the number of the last line in the textedit(te). Therefore Iam unable to get any text in "line". Is there any method (or what is the possible step) that I can follow to make it working?

    Thanks and Regards,
    Sarma.

  11. #11
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    5,372
    Thanks
    28
    Thanked 976 Times in 912 Posts
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11 Windows

    Default Re: MouseEvent on QTextEdit

    Where is that code snippet located? Is it from event filter?

  12. #12
    Join Date
    Mar 2006
    Location
    Hyderabad
    Posts
    69
    Thanks
    5
    Thanked 1 Time in 1 Post
    Qt products
    Qt3
    Platforms
    Unix/X11

    Default Re: MouseEvent on QTextEdit

    see the thread by name "How to change paragraph number in QTextEdit?"

  13. #13
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    5,372
    Thanks
    28
    Thanked 976 Times in 912 Posts
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11 Windows

    Default Re: MouseEvent on QTextEdit

    Quote Originally Posted by Sarma
    see the thread by name "How to change paragraph number in QTextEdit?"
    But in what method that code snippet is located? And why did you open another thread, if it is the same problem?

  14. #14
    Join Date
    Mar 2006
    Location
    Hyderabad
    Posts
    69
    Thanks
    5
    Thanked 1 Time in 1 Post
    Qt products
    Qt3
    Platforms
    Unix/X11

    Default Re: MouseEvent on QTextEdit

    hi,
    I think you didnot see the code correctly. There is only one if-condition , present in the code. And I have posted a new thread as It has become a different problem now.

    regards,
    Sarma.

  15. #15
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    5,372
    Thanks
    28
    Thanked 976 Times in 912 Posts
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11 Windows

    Default Re: MouseEvent on QTextEdit

    Quote Originally Posted by Sarma
    There is only one if-condition , present in the code.
    But in what method did you place that if statement?

Similar Threads

  1. QTextEdit Performance handling large paragraphs
    By netuno in forum Qt Programming
    Replies: 14
    Last Post: 1st September 2010, 22:58
  2. Drawing on QTextEdit
    By jgrauman in forum Qt Programming
    Replies: 3
    Last Post: 7th February 2009, 09:40
  3. QTextEdit slow to insert text
    By thomaspu in forum Qt Programming
    Replies: 4
    Last Post: 10th January 2008, 12:05
  4. QTextEdit API questions (plain text)
    By Gaspar in forum Qt Programming
    Replies: 4
    Last Post: 16th May 2006, 06:03
  5. MouseEvent & QTextEdit
    By Sarma in forum Qt Programming
    Replies: 2
    Last Post: 7th March 2006, 23:06

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Digia, Qt and their respective logos are trademarks of Digia Plc in Finland and/or other countries worldwide.