Results 1 to 3 of 3

Thread: QPlainTextEdit reimplementation

  1. #1
    Join Date
    May 2012
    Posts
    99
    Thanked 3 Times in 3 Posts
    Qt products
    Qt4
    Platforms
    Windows

    Question QPlainTextEdit reimplementation

    Hi all,

    I have reimplemented a QPlainTextEdit class to get the text inserted by the user, my code:

    Qt Code:
    1. #ifndef PLAINTEXTEDIT_H
    2. #define PLAINTEXTEDIT_H
    3.  
    4. #include <QPlainTextEdit>
    5.  
    6. namespace Ui {
    7. class GPlainTextEdit;
    8. }
    9.  
    10. class GPlainTextEdit : public QPlainTextEdit
    11. {
    12. Q_OBJECT
    13.  
    14. public:
    15. explicit GPlainTextEdit(QWidget *parent = 0);
    16. ~GPlainTextEdit();
    17.  
    18. protected:
    19. void keyPressEvent(QKeyEvent *e);
    20.  
    21. private:
    22. Ui::GPlainTextEdit *ui;
    23. };
    24.  
    25. #endif // PLAINTEXTEDIT_H
    To copy to clipboard, switch view to plain text mode 

    Qt Code:
    1. #include "gplaintextedit.h"
    2. #include "ui_gplaintextedit.h"
    3.  
    4. #include <QDebug>
    5.  
    6. GPlainTextEdit::GPlainTextEdit(QWidget *parent) :
    7. QPlainTextEdit(parent),
    8. ui(new Ui::GPlainTextEdit)
    9. {
    10. ui->setupUi(this);
    11.  
    12. connect(this, SIGNAL(textChanged()), this, SLOT(onCustomContextMenuRequested()));
    13. qDebug() << "GPlainTextEdit::GPlainTextEdit()";
    14. }
    15.  
    16. GPlainTextEdit::~GPlainTextEdit()
    17. {
    18. delete ui;
    19. }
    20.  
    21. void GPlainTextEdit::keyPressEvent(QKeyEvent *e)
    22. {
    23. qDebug() << "GPlainTextEdit::keyPressEvent(QKeyEvent *e)";
    24. }
    To copy to clipboard, switch view to plain text mode 

    Qt Code:
    1. <?xml version="1.0" encoding="UTF-8"?>
    2. <ui version="4.0">
    3. <class>GPlainTextEdit</class>
    4. <widget class="QPlainTextEdit" name="GPlainTextEdit">
    5. <property name="geometry">
    6. <rect>
    7. <x>0</x>
    8. <y>0</y>
    9. <width>104</width>
    10. <height>64</height>
    11. </rect>
    12. </property>
    13. </widget>
    14. <resources/>
    15. <connections/>
    16. </ui>
    To copy to clipboard, switch view to plain text mode 

    Then, in another widget, I have created a promoted widget using the reimplemented class, but the method 'keyPressEvent(QKeyEvent *e)' is not called.

    I have put a log in the GPlainTextEdit constructor, but it isn't shown.

    I have used the debugger in the QPlainTextEdit constructor call, but I can't step into.

    Any help is appreciated.

    Best regards.

  2. #2
    Join Date
    Sep 2011
    Posts
    1,241
    Thanks
    3
    Thanked 127 Times in 126 Posts
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: QPlainTextEdit reimplementation

    all of that probably means your widget is never created. show more code (read my sig)!
    If you have a problem, CUT and PASTE your code. Do not retype or simplify it. Give a COMPLETE and COMPILABLE example of your problem. Otherwise we are all guessing the problem from a fabrication where relevant details are often missing.

  3. #3
    Join Date
    May 2012
    Posts
    99
    Thanked 3 Times in 3 Posts
    Qt products
    Qt4
    Platforms
    Windows

    Cool Re: QPlainTextEdit reimplementation

    I have made clean + run qmake and now works properly.

Similar Threads

  1. QApplication::notify reimplementation
    By sa5webber in forum Newbie
    Replies: 0
    Last Post: 30th August 2012, 23:00
  2. Replies: 5
    Last Post: 18th July 2012, 09:17
  3. Replies: 5
    Last Post: 29th August 2011, 17:26
  4. QHeaderView paintSection reimplementation
    By supergillis in forum Qt Programming
    Replies: 3
    Last Post: 26th November 2008, 17:16
  5. keyPressEvent() reimplementation
    By aurelius in forum Newbie
    Replies: 5
    Last Post: 30th October 2008, 16:23

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.