1
我已經子類QLabel如下:文字環繞在使用樣式表不起作用
class TestLabel: public QLabel
{
Q_OBJECT
public:
TestLabel(QWidget *parent = 0):QLabel(parent){}
TestLabel(const QString& text, QWidget *parent = 0):QLabel(text, parent){}
protected:
void paintEvent(QPaintEvent *paint)
{
QStyleOption opt;
opt.init(this);
QPainter p(this);
style()->drawPrimitive(QStyle::PE_Widget, &opt, &p, this);
style()->drawItemText(&p,this->rect(),Qt::AlignLeft, (this->palette()), true, this->text());
}
};
我已經安裝了樣式表如下:
TestLabel {
font-size: 16px;
color: rgb(127, 127, 127);
}
我試圖通過文本換行使用:tlab->setWordWrap(true);
重寫paintEvent之前,文本被正確包裝。但是現在,文本不再被包裝。 documentation表示「文本根據標誌對齊幷包裝。」,但我如何通過這兩個標誌(他們都是不同的枚舉)?