Page 2 of 2 FirstFirst 12
Results 21 to 23 of 23

Thread: Call Constructor within Designer

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

    Default Re: Call Constructor within Designer

    You forgot the Q_OBJECT macro.
    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.


  2. #22
    Join Date
    Jan 2006
    Location
    Germany
    Posts
    4,380
    Thanks
    19
    Thanked 1,005 Times in 913 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows Symbian S60
    Wiki edits
    5

    Default Re: Call Constructor within Designer

    • use Q_OBJECT in your class OwnButton
    • use the right property name in the designer! (MyImage not setImate)

    and then, if you set QPixmap as a value in the custom property folowing is created:
    Qt Code:
    1. pushButton->setProperty("MyImage", QVariant(QPixmap(QString::fromUtf8(":/button_1.png"))));
    To copy to clipboard, switch view to plain text mode 
    So you have to provide QPixmap-setter like in your first code post, but also inside the Q_PROPERTY! then it works.

  3. #23
    Join Date
    Apr 2008
    Posts
    196
    Thanked 8 Times in 6 Posts
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11 Windows
    Wiki edits
    1

    Default Re: Call Constructor within Designer

    Ok, many thanks

    For those who also problems with this have, here is the corrected class:

    ownbutton.h:
    Qt Code:
    1. #ifndef OWNBUTTON_H
    2. #define OWNBUTTON_H
    3.  
    4. #include <QtGui>
    5. #include <QPixmap>
    6.  
    7. class OwnButton : public QPushButton {
    8. Q_OBJECT
    9. Q_PROPERTY(QPixmap pixmap READ pixmap WRITE setPixmap)
    10.  
    11. public:
    12. OwnButton(QWidget *parent = 0);
    13. QSize sizeHint() const;
    14. QSize minimumSizeHint() const;
    15. const QPixmap *pixmap() const;
    16. virtual void setPixmap(const QPixmap &image);
    17.  
    18. protected:
    19. void paintEvent(QPaintEvent *event);
    20.  
    21. private:
    22. QPixmap _pixmap;
    23. };
    24.  
    25. #endif // OWNBUTTON_H
    To copy to clipboard, switch view to plain text mode 
    ownbutton.cpp:
    Qt Code:
    1. #include "ownbutton.h"
    2. #include <QtGui>
    3.  
    4. OwnButton::OwnButton(QWidget *parent) : QPushButton(parent) {
    5. }
    6.  
    7. QSize OwnButton::sizeHint() const {
    8. return QSize(_pixmap.width(), _pixmap.height());
    9. }
    10.  
    11. QSize OwnButton::minimumSizeHint() const {
    12. return QSize(_pixmap.width(), _pixmap.height());
    13. }
    14.  
    15. void OwnButton::paintEvent(QPaintEvent *event) {
    16. QPainter painter(this);
    17.  
    18. painter.drawPixmap(0, 0, _pixmap.size().width(), _pixmap.size().height(), _pixmap);
    19. painter.drawRect(0, 0, _pixmap.size().width()-1, _pixmap.size().height()-1);
    20. }
    21.  
    22. const QPixmap *OwnButton::pixmap() const {
    23. return &_pixmap;
    24. }
    25.  
    26. void OwnButton::setPixmap(const QPixmap &image) {
    27. _pixmap = image;
    28. this->resize(_pixmap.size().width(), _pixmap.size().height());
    29. QWidget::updateGeometry();
    30. }
    To copy to clipboard, switch view to plain text mode 

    Regards
    NoRulez

Similar Threads

  1. designer not showing menu items ...
    By wagmare in forum Installation and Deployment
    Replies: 0
    Last Post: 24th February 2009, 10:26
  2. wwwidgets.how can it be brought into designer as plugin
    By sh123 in forum Installation and Deployment
    Replies: 1
    Last Post: 21st February 2009, 12:56
  3. Replies: 13
    Last Post: 15th December 2006, 11:52
  4. Designer crashes when selecting some widgets
    By gwendal in forum Qt Tools
    Replies: 4
    Last Post: 21st July 2006, 13:18
  5. How to create custom slot in Qt Designer 4.1?
    By jamadagni in forum Qt Tools
    Replies: 31
    Last Post: 18th January 2006, 20:46

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.