1

I wrote a simple Dialog example and tried to add an outline to QLineEdit, but there is no effect.

#include "mainwindow.h"
#include <QLineEdit>
#include <QVBoxLayout>

MainWindow::MainWindow(QWidget *parent) :
    QDialog(parent)
{
   auto layout = new QVBoxLayout(this);
   auto lineEdit = new QLineEdit(this);
   lineEdit->setStyleSheet("QLineEdit { outline-color: red; } ");

   layout->addWidget(lineEdit, 0, Qt::AlignCenter);

   setLayout(layout);
}

what am I doing wrong?

1 Answers1

1

Is this what you want to achieve?

lineEdit->setStyleSheet("border: 1px solid red");

Edit:

It really seems that the outline feature does not work as expected although it is documented in the reference. I think it is documentation bug because it was introduced afterwards, see QTBUG-26673. The outline in the example is for QPushButtons and does a different job than the outline CSS defines. You can see other examples for that here on SO, see: QT - CSS: decoration on focus So in summary I would conclude that the outline property is wrongly documented and can not be used for your purpose. You can file in Qt Bug report and see what the outcome is.

Taron
  • 1,205
  • 2
  • 13
  • 29