QLabel: set color of text and background

后端 未结 6 1641
清歌不尽
清歌不尽 2020-11-30 20:03

How do I set color of text and background of a QLabel ?

6条回答
  •  死守一世寂寞
    2020-11-30 20:37

    This one is working perfect

    QColorDialog *dialog = new QColorDialog(this);
    QColor color=  dialog->getColor();
    QVariant variant= color;
    QString colcode = variant.toString();
    ui->label->setStyleSheet("QLabel { background-color :"+colcode+" ; color : blue; }");
    

    getColor() method returns the selected color. You can change label color using stylesheet

提交回复
热议问题