QLabel 在左邊添加小圖標

不廢話,直接上代碼:

m_plbTip = new QLabel(this);
    LedtLeftBtnFactory fac;
    QPushButton * pbtnIco = fac.buildIcoBtn(this,":/Login/tipIcon.png");
    QImage img(":/Login/tipIcon.png");
    pbtnIco->setFixedSize(img.size());


    QHBoxLayout * pLay = new QHBoxLayout();
    pLay->setContentsMargins(0,0,0,0);
    pLay->addSpacing(5);
    pLay->addWidget(pbtnIco);
    pLay->addStretch(5);
    m_plbTip->setLayout(pLay);
    m_plbTip->setContentsMargins(0,10,10,10);

    //m_plbTip->setFixedSize(270,38);
    m_plbTip->hide();

    m_plbTip->setStyleSheet("color:#cc0000;background-color:#fff9ef;border-width: 1px;border-style: solid;border-color: #ff5b5b;");

如果只有上面的代碼,則出來的效果的文字的左邊會被遮擋,因此我們在setText時,要添加一些空格

void LoginViewUI::ShowTip(QString str){

    m_plbTip->setText("   "+str);
    m_plbTip->show();
}

效果圖


發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章