9

I'm styling a QLineEdit to have rounded borders for use as a search box. The rounding of the borders themselves were easy, but I can't figure out for the life of me how to round the highlighted portion of the widget when it has focus. I've tried QLineEdit::focus, but this only modifies the interior border. The images below show how the illusion of a rounded qlineedit is lost when it gains focus.

QListView, QLineEdit {
    color: rgb(127, 0, 63);
    selection-color: white;   
    border: 2px groove gray;
    border-radius: 10px;
    padding: 2px 4px;
}
QLineEdit:focus {
    color: rgb(127, 0, 63);
    selection-color: white;   
    border: 2px groove gray;
    border-radius: 10px;
    padding: 2px 4px;
}

QLineEdit:edit-focus {
    color: rgb(127, 0, 63);
    selection-color: white;   
    border: 2px groove gray;
    border-radius: 10px;
    padding: 2px 4px;
}

Images with and without focus: without with

Glorfindel
  • 21,988
  • 13
  • 81
  • 109
jkyle
  • 2,002
  • 1
  • 18
  • 23

2 Answers2

5

On the Mac:

widget.setAttribute(Qt::WA_MacShowFocusRect, 0);

should work, see this answer. Otherwise you will have to subclass QStyle and remove the drawing of the focus rectangle there. See Nokia FAQ 736 (How to avoid drawing focus rect)

Community
  • 1
  • 1
Harald Scheirich
  • 9,676
  • 29
  • 53
-1

Styling QLineEdit:focus appropriately should take care of your problem see Qt Stylesheet Reference, List of Pseudo States

Harald Scheirich
  • 9,676
  • 29
  • 53
  • The pseudo state only effects the actual border, not the external border. It's possible I'm not using it appropriately. I've added my QLineEdit:focus and QLineEdit:edit-focus styles. The pics remain the same. – jkyle Apr 15 '10 at 01:11
  • Yes you are right, this actually changes the style of the widget when the focus is on the widget, it does not affect the focus rect, adding a better answer, leaving this for reference – Harald Scheirich Apr 15 '10 at 02:52