Results 1 to 5 of 5

Thread: Unable to write in QTextEdit

  1. #1
    Join Date
    Oct 2015
    Posts
    18
    Qt products
    Qt4 Qt5 Qt/Embedded
    Platforms
    Windows

    Default Unable to write in QTextEdit

    I wrote new class inherited from QTextEdit and have keypressevent inside my class called "MyTextEdit.cpp"

    Now I want to use this in other class called "MyEditor.cpp", so i created an object of MyTextEdit class and set the setReadOnly() property to false. But it not allow me to write in textedit. I also set it to setEnabled() to true. But still facing same issue.

    I think i am missing something or made some silly mistake.

    Can anyone let me know what i am doing wrong here.

  2. #2
    Join Date
    Jan 2006
    Location
    Graz, Austria
    Posts
    8,420
    Thanks
    37
    Thanked 1,545 Times in 1,495 Posts
    Qt products
    Qt3 Qt4 Qt5
    Platforms
    Unix/X11 Windows

    Default Re: Unable to write in QTextEdit

    In your keyPressEvent() method, do you call the base class implementation?

    Cheers,
    _

  3. #3
    Join Date
    Oct 2015
    Posts
    18
    Qt products
    Qt4 Qt5 Qt/Embedded
    Platforms
    Windows

    Default Re: Unable to write in QTextEdit

    Yah, but textedit itself not writable, although I can call my kerypressevent, which is not an issue. Issue is i not even get textEdit as writable/editable.

  4. #4
    Join Date
    Mar 2009
    Location
    Brisbane, Australia
    Posts
    7,590
    Thanks
    13
    Thanked 1,586 Times in 1,515 Posts
    Qt products
    Qt4 Qt5
    Platforms
    Unix/X11 Windows
    Wiki edits
    17

    Default Re: Unable to write in QTextEdit

    What you are describing is captured below:
    Qt Code:
    1. #include <QApplication>
    2. #include <QTextEdit>
    3. #include <QDebug>
    4.  
    5. class MyTextEdit: public QTextEdit
    6. {
    7. Q_OBJECT
    8. public:
    9. MyTextEdit(QWidget *p = 0): QTextEdit(p) { }
    10. protected:
    11. void keyPressEvent(QKeyEvent *event) {
    12. // do local stuff
    13. qDebug() << "Doing local stuff";
    14. // then do the base stuff
    15. QTextEdit::keyPressEvent(event);
    16. }
    17. };
    18.  
    19. int main(int argc, char **argv) {
    20. QApplication app(argc, argv);
    21. MyTextEdit edit; // defaults to editable
    22. edit.show();
    23. return app.exec();
    24. }
    25. #include "main.moc"
    To copy to clipboard, switch view to plain text mode 
    and this works. So, is this what you are doing?

  5. #5
    Join Date
    Oct 2015
    Posts
    18
    Qt products
    Qt4 Qt5 Qt/Embedded
    Platforms
    Windows

    Default Re: Unable to write in QTextEdit

    yah thanks.

    But what you explained, I previously done same thing. And it works if it is as standalone program. But when I do same thing in my application , its not work. and not allows me to edit or write ??


    Added after 1 14 minutes:


    THANKS TO BOTH OF YOU to suggest me some solution.

    But I figure out it. I don't know the exact issue, but i tried to re-write my code, it got worked.

    Really a Wiered one. In end it got work. lol
    Last edited by dikku; 30th December 2015 at 11:07.

Similar Threads

  1. Replies: 0
    Last Post: 24th April 2014, 09:54
  2. Circular reference ... Unable to write forwarding
    By tonnot in forum General Programming
    Replies: 6
    Last Post: 27th June 2011, 12:26
  3. Replies: 2
    Last Post: 2nd November 2010, 06:15
  4. Unable to write to file QFile
    By cuter in forum Qt Programming
    Replies: 4
    Last Post: 15th July 2009, 12:19
  5. Replies: 1
    Last Post: 16th February 2007, 08:22

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
  •  
Digia, Qt and their respective logos are trademarks of Digia Plc in Finland and/or other countries worldwide.