How to place an icon onto a QLineEdit?

后端 未结 7 1033
终归单人心
终归单人心 2021-02-08 07:09

There is a Search field with the magnification-lens and a greyed out \"search\" keyword at the top right corner of stackoverflow.com web site:

7条回答
  •  没有蜡笔的小新
    2021-02-08 07:45

    Here's a way to achieve this with stylesheets only:

    QLineEdit {
        background: #f3f3f3;
        background-image: url(:Images/search.svg); /* actual size, e.g. 16x16 */
        background-repeat: no-repeat;
        background-position: left;
        color: #252424;
        font-family: SegoeUI;
        font-size: 12px;
        padding: 2 2 2 20; /* left padding (last number) must be more than the icon's width */
    }
    

    Here's the result:

    It's still not perfect. You don't have much influence over the icon's position.

提交回复
热议问题