如何缩小 LineEdit 中的按钮大小?

How to make size of button in the LineEdit smaller?

我在LineEdit中制作了X按钮,当我点击这个按钮时,LineEdit是清晰的。但是用我的方法,X按钮看起来有点大,不美观,我需要把它变小。我该怎么做?

myLineEdit = new LineEdit;
myLineEdit->setFixedHeight( 25 );
m_clear = m_lineEdit->addAction( QIcon( ":/clearButton" ), QLineEdit::TrailingPosition );

clearButton.png的大小是12x12px,所以在这个例子中放大了,看起来不那么漂亮。

对于这个解决方案,假设在原始图像中前景大小和背景之间的关系是1:1(这在图标中是正常的),所以解决方案是增加这种关系,为此我们创建新图像

QPixmap in(":/clearButton");
QPixmap out(in.size()*10/7);
QRect r= in.rect();
r.moveCenter(out.rect().center());
out.fill(Qt::transparent);

QPainter painter(&out);
painter.drawPixmap(r , in);
painter.end();

QLineEdit *m_lineEdit = new QLineEdit;
m_lineEdit->setFixedHeight(25);
m_lineEdit->addAction(QIcon(out), QLineEdit::TrailingPosition);

之前:

之后: