I'm trying to create a custom shape QLineEdit
with QWidget::setMask()
. I redefined resizeEvent
for my sub class 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. Btw, it was added to a QGridlayout
and I checked that pixmap.isNull() == false
and the size was normal. 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"
"}");
editor->setStyleSheet("QLineEdit {\n"
" border-image: url(:/new/prefix1/region.png) 3 3 3 3;\n"
"}");
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.