[英]qt change QLineEdit shape
I'm trying to create a custom shape QLineEdit
with QWidget::setMask()
. 我正在尝试使用
QWidget::setMask()
创建自定义形状QLineEdit
。 I redefined resizeEvent
for my sub class lineEdit
. 我重新定义
resizeEvent
我的子类lineEdit
。
void MyLineEdit::resizeEvent(QResizeEvent *ev)
{
QPixmap pixmap(":/new/prefix1/region.png");
setFixedSize(ev->size());
setMask(pixmap.mask());
setStyleSheet("background-color : gray");
}
But the QlineEdit
isn't showed. 但是没有显示
QlineEdit
。 Btw, it was added to a QGridlayout
and I checked that pixmap.isNull() == false
and the size was normal. 顺便说一句,它被添加到一个
QGridlayout
,我检查pixmap.isNull() == false
和大小正常。 Did I miss something? 我错过了什么? Why isn't it displayed?
为什么不显示?
You don't have to subclass anything. 您不必继承任何子类。 Just use style sheets .
只需使用样式表即可 。
editor->setStyleSheet("QLineEdit {\n"
" background: url(:/new/prefix1/region.png);\n"
"}");
or based on documentation : 或根据文档 :
editor->setStyleSheet("QLineEdit {\n"
" border-image: url(:/new/prefix1/region.png) 3 3 3 3;\n"
"}");
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.