Results 1 to 4 of 4

Thread: QPixmap in QPushButton size problem

  1. #1
    Join Date
    Jan 2006
    Location
    Ljubljana
    Posts
    687
    Thanks
    111
    Thanked 4 Times in 4 Posts
    Qt products
    Qt5 Qt/Embedded
    Platforms
    MacOS X Unix/X11 Windows Android

    Red face QPixmap in QPushButton size problem

    Hi to all!

    I've subclassed QPushButton and for the start I would like to resize this god damn QPixmap in subclassed QPushButton! I've been trying for a whole day and I cannot get it to work. Can someone help me?!
    Qt 5.3 Opensource & Creator 3.1.2

  2. #2
    Join Date
    Aug 2007
    Location
    Gorakhpur, India
    Posts
    254
    Thanks
    8
    Thanked 14 Times in 14 Posts
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11

    Default Re: QPixmap in QPushButton size problem

    Like MarkoSan, I am facing the same problem using the following code;
    Qt Code:
    1. #include <QtGui>
    2. int main (int argc, char **argv)
    3. {
    4.  
    5. QApplication app(argc,argv);
    6.  
    7. QPixmap *p=new QPixmap("plane.jpg");
    8. QPixmap *p1=new QPixmap(p->scaled ( 30,20, Qt::IgnoreAspectRatio, Qt::SmoothTransformation ));
    9. QPalette palBack;
    10. QBrush brush(*p1);
    11. brush.setStyle(Qt::TexturePattern);
    12. palBack.setBrush(QPalette::Active, QPalette::Button, brush);
    13. palBack.setBrush(QPalette::Inactive, QPalette::Button, brush);
    14. palBack.setBrush(QPalette::Active, QPalette::Window, brush);
    15. palBack.setBrush(QPalette::Inactive, QPalette::Window, brush);
    16.  
    17. QBrush brush1(QColor(255, 255, 255, 255));
    18. brush1.setStyle(Qt::SolidPattern);
    19. palBack.setBrush(QPalette::Disabled, QPalette::Button, brush1);
    20. palBack.setBrush(QPalette::Disabled, QPalette::Window, brush1);
    21.  
    22. w.setPalette(palBack);
    23. QPushButton *lab=new QPushButton(&w);
    24. lab->setGeometry(30,30,40,30);
    25.  
    26.  
    27. lab->setPalette(palBack);
    28. lab->setAutoFillBackground (true);
    29. w.show();
    30. w.setFixedSize(300,200);
    31. return app.exec();
    32. }
    To copy to clipboard, switch view to plain text mode 
    By using above I am getting the black push button in spite of "plane.jpg". However It is working well for QWidget background. Any help or advice is highly respected.
    Anurag Shukla
    A man who never makes mistake is the man who never does anything! Theodre Rosvelt!

  3. #3
    Join Date
    Aug 2007
    Location
    Gorakhpur, India
    Posts
    254
    Thanks
    8
    Thanked 14 Times in 14 Posts
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11

    Default Re: QPixmap in QPushButton size problem

    Output is attached.
    Attached Images Attached Images
    Anurag Shukla
    A man who never makes mistake is the man who never does anything! Theodre Rosvelt!

  4. #4
    Join Date
    Jan 2006
    Location
    Ljubljana
    Posts
    687
    Thanks
    111
    Thanked 4 Times in 4 Posts
    Qt products
    Qt5 Qt/Embedded
    Platforms
    MacOS X Unix/X11 Windows Android

    Default Re: QPixmap in QPushButton size problem

    I managed it to work!!!

    setIconSize must be used.
    Qt 5.3 Opensource & Creator 3.1.2

Similar Threads

  1. Simple Problem with QFont (point size)
    By mtrpoland in forum Newbie
    Replies: 4
    Last Post: 31st December 2007, 16:49
  2. QLabel size policy
    By Caius Aérobus in forum Qt Programming
    Replies: 3
    Last Post: 7th December 2007, 17:57
  3. QPushButton problem
    By sincnarf in forum Qt Programming
    Replies: 4
    Last Post: 20th August 2007, 21:02
  4. QPushbutton problem
    By amulya in forum Qt Programming
    Replies: 5
    Last Post: 30th August 2006, 08:11
  5. Qt 4.1.1 linker warnings
    By Matt Smith in forum Installation and Deployment
    Replies: 0
    Last Post: 26th February 2006, 22:14

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.