Results 1 to 8 of 8

Thread: Simulate mouse click inside QTextEdit in Qt?

Hybrid View

Previous Post Previous Post   Next Post Next Post
  1. #1
    Join Date
    May 2015
    Posts
    5
    Qt products
    Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Android

    Default Simulate mouse click inside QTextEdit in Qt?

    I am trying to simulate a mouse click inside a QTextEdit in Qt as my application does not have any mouse or keyboard. This is an Embedded hardware board.

    Qt Code:
    1. int main(int argc, char *argv[])
    2. {
    3.  
    4. QApplication a(argc, argv);
    5. MainWindow w;
    6. w.setWindowFlags(Qt::Window | Qt::FramelessWindowHint);
    7. w.setStyleSheet("background-color: Black;");
    8. w.startcomthread();
    9. w.show();
    10.  
    11.  
    12. QTextEdit *txt = new QTextEdit();
    13. txt->setWindowFlags(Qt::Window | Qt::FramelessWindowHint);
    14. txt->setFocus();
    15. txt->setStyleSheet("background-color: rgb(255, 255, 255,200);");
    16. txt->setGeometry(10,20,100,30);
    17. txt->setText("Text 1");
    18.  
    19. QCursor::setPos((txt->pos()+=QPoint(10,10)));
    20. QMouseEvent * event1 = new QMouseEvent ((QEvent::MouseButtonPress), QPoint(10,10),
    21. Qt::LeftButton,
    22. Qt::LeftButton,
    23. Qt::NoModifier);
    24.  
    25. qApp->postEvent((QObject*)txt,(QEvent *)event1);
    26.  
    27. QMouseEvent * event2 = new QMouseEvent ((QEvent::MouseButtonRelease), QPoint(10,10),
    28. Qt::LeftButton,
    29. Qt::LeftButton,
    30. Qt::NoModifier);
    31.  
    32. qApp->postEvent((QObject*)txt,(QEvent *)event2);
    33.  
    34.  
    35. txt->show();
    36.  
    37. return a.exec();
    38. }
    To copy to clipboard, switch view to plain text mode 



    When I run the application, I just see a Cursor on my textedit box.I want the cursor to be clicked / at-least cursor should be blinking inside textedit widget.

    Thank you.
    Last edited by vk41286; 10th June 2015 at 08:32.

  2. #2
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,373
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Thanks
    3
    Thanked 5,019 Times in 4,795 Posts
    Wiki edits
    10

    Default Re: Simulate mouse click inside QTextEdit in Qt?

    Quote Originally Posted by vk41286 View Post
    I am trying to simulate a mouse click inside a QTextEdit in Qt
    Are you sure this is really what you want? Maybe instead you want the widget to gain focus or maybe you want to position the text cursor in a given position? Which is it then?
    Your biological and technological distinctiveness will be added to our own. Resistance is futile.

    Please ask Qt related questions on the forum and not using private messages or visitor messages.


Similar Threads

  1. How to simulate QTouchEvent using mouse
    By dpatel in forum Qt Programming
    Replies: 5
    Last Post: 28th April 2016, 01:40
  2. Simulate mouse click
    By Merylin in forum Qt Programming
    Replies: 8
    Last Post: 18th March 2014, 03:27
  3. how to simulate mouse click behavior?
    By hashb in forum Qt Programming
    Replies: 2
    Last Post: 31st August 2010, 07:53
  4. Replies: 4
    Last Post: 15th March 2010, 14:49
  5. Replies: 1
    Last Post: 18th December 2009, 20:57

Tags for this Thread

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
  •  
Qt is a trademark of The Qt Company.