Annoying background item problem

This what it looks like

this is my stylesheet:

QLineEdit#SearchBarEditBox {
    background: white;
    background-image: url(:/images/magnifyingGlass.png);
    background-repeat: no-repeat;
    background-position: 5px 5px;
}

My problem: "background-position" only gets the values ​​"top / bottom / right / left". Any attempt to use a numerical absolute value immediately arises in justifying the "upper center" for my image. Here is crazy ....

+3
source share
2 answers

Qt style sheets do not implement full CSS, you can use center/top/left/bottom/rightfor background-position.

See background-position and alignment in the Qt style reference.

+3
source

Although this is an old question, I would like to answer for those who have the same problem today.

, background-origin:

angular , background-position background-image. [...] , .

:

#QLineEdit#SearchBarEditBox{
    background-color: #FFFFFF;
    border-radius: 12px;
    border: 1px solid #DEDEDE;
    padding: 4px 4px 4px 10px; /* top - right - bottom - left */
    background-image: url(:/icons/search.png);
    background-repeat: no-repeat;
    background-position: left center;
    background-origin: content; /* the left margin of background image will 'obey' the padding-left defined up above (10px) */
}

Result

"10px" "30px", , .

, :)

0

Source: https://habr.com/ru/post/1796394/


All Articles