Results 1 to 1 of 1

Thread: how to stretch background image of pushbutton on button resize?

  1. #1
    Join Date
    Jul 2011
    Posts
    81
    Thanks
    8
    Thanked 2 Times in 2 Posts
    Qt products
    Qt4
    Platforms
    Windows Symbian S60 Maemo/MeeGo

    Default Re: how to stretch background image of pushbutton on button resize?

    how to stretch background image of pushbutton on button resize?

    i tryed this code. But not worked at all. its works for frame, central widgets, labels but not working on pushbutton


    Qt Code:
    1. void MainWindow::resizeEvent(QResizeEvent *e)
    2. {
    3. ui->centralWidget->setGeometry(0,0,e->size().width(),e->size().height());
    4. ui->pushButton->setGeometry(0,0,(e->size().width())/2,(e->size().height())/2);
    5. QPalette let = ui->pushButton->palette();
    6. QSize size(ui->pushButton->width(),ui->pushButton->height());
    7. QString main=":/M_alertBtncontinueUpNews.png";
    8. QPixmap pixmapmain1(main);
    9. QPixmap pixmapmain(pixmapmain1.scaled(size));
    10. let.setBrush(QPalette::Background,pixmapmain);
    11. ui->pushButton->setPalette(let);
    12. ui->pushButton->setAutoFillBackground(true);
    13. }
    To copy to clipboard, switch view to plain text mode 


    Added after 22 minutes:


    i got the code...
    this worked for me
    Qt Code:
    1. ui->centralWidget->setGeometry(0,0,e->size().width(),e->size().height());
    2. ui->pushButton->setGeometry(0,0,(e->size().width())/2,(e->size().height())/2);
    3. QPixmap* extpixmap = new QPixmap(":/M_alertBtncontinueUpNews.png");
    4. QSize size2(ui->pushButton->width(),ui->pushButton->height());
    5. QPixmap pixmapmain2(extpixmap->scaled(size2));
    6. QIcon exticon(pixmapmain2);
    7. ui->pushButton->setIconSize(size2);
    8. ui->pushButton->setIcon(exticon);
    To copy to clipboard, switch view to plain text mode 
    Last edited by athulms; 29th September 2011 at 09:41.

Similar Threads

  1. How to resize pushbutton to fit text?
    By Dreamerzz in forum Qt Programming
    Replies: 9
    Last Post: 16th May 2012, 13:01
  2. Replies: 3
    Last Post: 29th April 2011, 08:54
  3. How to stretch background image used in brush-palette
    By Hookem in forum Qt Programming
    Replies: 5
    Last Post: 24th December 2008, 17:03
  4. Resize event on stretch?
    By kodiak in forum Qt Programming
    Replies: 2
    Last Post: 3rd November 2008, 22:51
  5. TextEdit won't resize when Stretch factor set to 0
    By bunjee in forum Qt Programming
    Replies: 1
    Last Post: 23rd January 2007, 17:51

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.