0

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?

AAEM
  • 1,837
  • 2
  • 18
  • 26
Mike Shaw
  • 373
  • 7
  • 22
  • 1
    http://qt-project.org/doc/qt-4.8/qwidget.html#resizeEvent "No drawing need be (or should be) done inside this handler.". Try ::paintEvent() – friendzis May 23 '14 at 14:12

1 Answers1

1

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"
                      "}");
Community
  • 1
  • 1
Marek R
  • 32,568
  • 6
  • 55
  • 140