Qt 4.6 QLineEdit风格。如何设置灰色高光边框的样式以使其圆润?

时间:2010-04-06 22:16:37

标签: qt qt4 qlineedit

我正在为QLineEdit设计样式以使用圆形边框作为搜索框。边界本身的舍入很容易,但我无法弄清楚如何在焦点有焦点的情况下围绕窗口小部件的突出显示部分。我尝试过QLineEdit :: focus,但这只会修改内部边框。下面的图片显示了圆角qlineedit在获得焦点时如何失去幻觉。

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;
}

有焦点和无焦点的图像: without http://img688.imageshack.us/img688/1986/screenshot20100406at310.png with http://img251.imageshack.us/img251/1986/screenshot20100406at310.png

2 个答案:

答案 0 :(得分:5)

在Mac上:

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

应该有效,请参阅this answer。否则,您必须继承QStyle并删除焦点矩形的绘图。见Nokia FAQ 736 (How to avoid drawing focus rect)

答案 1 :(得分:-1)

样式QLineEdit:focus应该正确处理您的问题,请参阅Qt Stylesheet Reference, List of Pseudo States