Qt tip Qlabel How to set a picture, the picture size is set to Qlabel equivalent size __QT

Source: Internet
Author: User

Sets the Qlabel fill picture and sets the size of a picture to the width and height of the Qlabel border.

Ui->dangqian_tianqi_img_label->width ()//is the width of the Qlabel
Ui->dangqian_tianqi_img_label->height ()//high for Qlabel

Qpixmap Tianqi_pixmap (":/img/ico/qing.png");
Qdebug () << tianqi_pixmap.width () << "/" << tianqi_pixmap.height ();
Tianqi_pixmap = tianqi_pixmap.scaled (Ui->dangqian_tianqi_img_label->width (), Ui->dangqian_tianqi_img_ Label->height (),
                                    qt::ignoreaspectratio, qt::smoothtransformation)//Set picture size and label long width consistent
ui-> Dangqian_tianqi_img_label->setpixmap (TIANQI_PIXMAP);
Ui->dangqian_tianqi_img_label->show ();

void Login::set_top_img (bool issandom, int index_img) {//427 185 int set_index_img = 1;
        if (Issandom = = true)//randomly displays topimg {qtime time_sand;

        time_sand= qtime::currenttime ()//Get the current time Qsrand (Time_sand.msec () +time_sand.second () *1000);  Index_img = Qrand ()%5//Select random number in 0-4 set_index_img = Qrand ()%5 + 1;//select random number in 1-5} if (Issandom = False)
    No random display, press index_img display picture s {set_index_img = index_img;
    } QString top_img_path= ":/images/top_img1.png";
    Qdebug () << "[Leo]" << Top_img_path;
    QImage top_img;
    Top_img_path = ":/images/top_img" + qstring::number (set_index_img, ten) + ". png";
    Qdebug () << "[Leo]" << Top_img_path;
    Top_img.load (Top_img_path); Qpixmap top_pic=qpixmap::fromimage (top_img.scaled (Ui->label_top_img->width (),ui->label_top_img->
    Height ()));
    Ui->label_top_img->setpixmap (Top_pic);         Qdebug () << " [Leo]top_img width heigh: "<< ui->label_top_img->width () <<" "<< ui->label_top_
Img->height (); }

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.