Results 1 to 2 of 2

Thread: Subclassing a QPushButton

  1. #1
    Join Date
    Sep 2013
    Posts
    1
    Qt products
    Qt4
    Platforms
    Windows

    Unhappy Subclassing a QPushButton

    I subclassed a QPushButton and in the constructor I changed the text of QPushButton however the text does not change in the actual button any suggestions on why the text is not changing ?
    Qt Code:
    1. #ifndef QCUSTOMPUSHBUTTON
    2. #define QCUSTOMPUSHBUTTON
    3.  
    4.  
    5. #include "QObject"
    6. #include "QPushButton"
    7.  
    8. class QCustomPushBtton : public QPushButton
    9. {
    10. Q_OBJECT
    11.  
    12. public:
    13. QCustomPushBtton(QWidget *parent=0):QPushButton(parent)
    14. {
    15. this->setText("testing123");
    16. }
    17.  
    18. signals:
    19. void DoubleClick();
    20.  
    21. protected:
    22. virtual void mouseDoubleClickEvent(QMouseEvent *) override
    23. {
    24. emit DoubleClick();
    25. }
    26. };
    27.  
    28.  
    29. #endif // QCUSTOMPUSHBUTTON
    To copy to clipboard, switch view to plain text mode 
    Last edited by Rajeshkhan; 3rd October 2015 at 23:38.

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

    Default Re: Subclassing a QPushButton

    Do you set text anywhere else?
    Have you confirmed that you are creating instances of your button?

    While that should not make any difference, you can also pass the text to the base class's constructor:
    Qt Code:
    1. QCustomPushBtton(QWidget *parent=0):QPushButton("testing123", parent)
    To copy to clipboard, switch view to plain text mode 

    Cheers,
    _

Similar Threads

  1. Subclassing QPushButton to support word wrapping
    By Berryblue031 in forum Qt Programming
    Replies: 7
    Last Post: 9th June 2011, 15:14
  2. Replies: 0
    Last Post: 22nd February 2010, 09:30
  3. Subclassing QWidget and QPushButton
    By ber0y in forum Newbie
    Replies: 7
    Last Post: 24th July 2009, 10:25
  4. Replies: 3
    Last Post: 26th September 2006, 12:16
  5. Subclassing
    By joseph in forum Newbie
    Replies: 1
    Last Post: 25th February 2006, 14:06

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.