Results 1 to 8 of 8

Thread: defining a widget from the ui file

Hybrid View

Previous Post Previous Post   Next Post Next Post
  1. #1
    Join Date
    Jan 2006
    Location
    Graz, Austria
    Posts
    8,416
    Qt products
    Qt3 Qt4 Qt5
    Platforms
    Unix/X11 Windows
    Thanks
    37
    Thanked 1,544 Times in 1,494 Posts

    Default Re: defining a widget from the ui file

    if you want your own QTextEdit subclass to be instantiated, you'll need to use the "promote widget" functionality.

    Make a proper header/source implementation of your text edit class and then specify that class and its header in designer when using the promote feature.

    Cheers,
    _

  2. The following user says thank you to anda_skoa for this useful post:

    ravas (23rd June 2015)

  3. #2
    Join Date
    Jun 2015
    Location
    California, USA
    Posts
    61
    Qt products
    Qt5
    Platforms
    MacOS X Unix/X11
    Thanks
    43
    Thanked 1 Time in 1 Post

    Default Re: defining a widget from the ui file

    Thanks. I can't seem to figure it out. I keep getting:

    Qt Code:
    1. C:\1A\2015\QT\build-QuickPad-Desktop_Qt_5_4_1_MinGW_32bit-Debug\ui_notepad.h:58: error: expected type-specifier before 'textEdit'
    2. textEdit = new textEdit(centralWidget);
    3. ^
    To copy to clipboard, switch view to plain text mode 

    textedit.h
    Qt Code:
    1. #ifndef TEXTEDIT_H
    2. #define TEXTEDIT_H
    3.  
    4. #include <QTextEdit>
    5.  
    6. namespace Ui {
    7. class textEdit;
    8. }
    9.  
    10. class textEdit : public QTextEdit
    11. {
    12. Q_OBJECT
    13.  
    14. public:
    15. explicit textEdit(QWidget *parent);
    16. ~textEdit();
    17.  
    18. private slots:
    19.  
    20. void mouseReleaseEvent(QMouseEvent *event);
    21.  
    22. private:
    23. Ui::textEdit *ui;
    24. };
    25.  
    26. #endif // TEXTEDIT_H
    To copy to clipboard, switch view to plain text mode 

    textedit.cpp

    Qt Code:
    1. #include "textedit.h"
    2.  
    3. textEdit::textEdit(QWidget *parent) :
    4. QTextEdit(parent),
    5. ui(new Ui::textEdit)
    6. {
    7. ui->setupUi(this);
    8. }
    9.  
    10. textEdit::~textEdit()
    11. {
    12. delete ui;
    13. }
    14.  
    15. void textEdit::mouseReleaseEvent(QMouseEvent *event)
    16. {
    17. copy();
    18. }
    To copy to clipboard, switch view to plain text mode 
    Last edited by ravas; 23rd June 2015 at 22:03.

  4. #3
    Join Date
    Jan 2006
    Location
    Graz, Austria
    Posts
    8,416
    Qt products
    Qt3 Qt4 Qt5
    Platforms
    Unix/X11 Windows
    Thanks
    37
    Thanked 1,544 Times in 1,494 Posts

    Default Re: defining a widget from the ui file

    You called your class "textEdit" and you seem to have used the very same character combination as the variable/object name in designer.

    Rename either the class or the object.

    Cheers,
    _

  5. The following user says thank you to anda_skoa for this useful post:

    ravas (23rd June 2015)

  6. #4
    Join Date
    Jun 2015
    Location
    California, USA
    Posts
    61
    Qt products
    Qt5
    Platforms
    MacOS X Unix/X11
    Thanks
    43
    Thanked 1 Time in 1 Post

    Default Re: defining a widget from the ui file

    I thought it needed to be the same.
    I got it working. Thank you!

    qtext.h

    Qt Code:
    1. #ifndef QTEXT_H
    2. #define QTEXT_H
    3.  
    4. #include <QTextEdit>
    5.  
    6. class qText : public QTextEdit
    7. {
    8. Q_OBJECT
    9.  
    10. public:
    11.  
    12. explicit qText(QWidget *parent);
    13.  
    14. private slots:
    15.  
    16. void mouseReleaseEvent(QMouseEvent *event);
    17.  
    18. };
    19.  
    20. #endif // QTEXT_H
    To copy to clipboard, switch view to plain text mode 

    qtext.cpp

    Qt Code:
    1. #include "qtext.h"
    2.  
    3. qText::qText(QWidget *parent) :
    4. QTextEdit(parent) {}
    5.  
    6. void qText::mouseReleaseEvent(QMouseEvent *event)
    7. {
    8. copy();
    9. QTextEdit::mouseReleaseEvent(event);
    10. }
    To copy to clipboard, switch view to plain text mode 

Similar Threads

  1. Replies: 4
    Last Post: 8th January 2013, 22:08
  2. Defining widget regions sensitive to mouse events?
    By kachofool in forum Qt Programming
    Replies: 1
    Last Post: 29th December 2010, 02:37
  3. defining number
    By mickey in forum General Programming
    Replies: 1
    Last Post: 1st February 2008, 07:19
  4. Replies: 6
    Last Post: 15th September 2007, 23:14
  5. Defining data format in c++
    By locus in forum General Programming
    Replies: 3
    Last Post: 13th April 2007, 20:40

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.