Qt实现LineEdit里添加图片

1. 

QAction *searchAction = new QAction(ui.LineEdit);
searchAction->setIcon(QIcon(":/resource/query.png"));
ui.LineEdit->addAction(searchAction,QLineEdit::TrailingPosition);
//QLineEdit::LeadingPosition 在左侧

2.

    m_KeyboardButton = new QPushButton();
    m_KeyboardButton->setFixedSize(QSize(16, 16));
    m_KeyboardButton->setCursor(QCursor(Qt::PointingHandCursor));

    QHBoxLayout* passwordEditLayout = new QHBoxLayout();
    passwordEditLayout->addStretch();
    passwordEditLayout->addWidget(m_KeyboardButton);
    passwordEditLayout->setSpacing(0);
    passwordEditLayout->setContentsMargins(0, 0, 8, 0);

    Password_Login_LineEdit->setLayout(passwordEditLayout);
    Password_Login_LineEdit->setTextMargins(0, 0, m_KeyboardButton->width() + 12, 0);

    m_KeyboardButton->setStyleSheet("QPushButton{border-image: url(:/new/prefix2/Pic/JPG/keyboard - back.png);}"
                                    "QPushButton:hover{border-image: url(:/new/prefix2/Pic/JPG/keyboard_hover.png);}"
                                    "QPushButton:pressed{border-image: url(:/new/prefix2/Pic/JPG/keyboard_press.png);}");

 

展开阅读全文

没有更多推荐了,返回首页