QIcon searchIcon(":/CJWidgt/Resources/search.png")
m_btnSearch->setStyleSheet("border-style:solid")
m_btnSearch->setFlat(true)
m_btnSearch->setIcon(searchIcon)
m_btnSearch->setIconSize(QSize(24,24))
m_btnSearch->setCursor(Qt::PointingHandCursor)
m_btnSearch->setFixedSize(24, 24)
m_btnSearch->setToolTip(QStringLiteral("查询"))
QMargins margins = ui.lineSearchContent->textMargins()
ui.lineSearchContent->setTextMargins(margins.left(), margins.top(), m_btnSearch->width(), margins.bottom())
QHBoxLayout *pSearchLayout = new QHBoxLayout()
pSearchLayout->addStretch()
pSearchLayout->addWidget(m_btnSearch)
pSearchLayout->setSpacing(0)
pSearchLayout->setContentsMargins(0, 0, 0, 0)
ui.lineSearchContent ->setLayout(pSearchLayout)
重新实现一下QLineEdit的keypressevent事件,然后捕获输入的按键,进行设置,具体可看此处。
void HotkeyLineEdit::keyPressEvent(QKeyEvent *event)
{
//捕获输入的键, 除了A-Z以及Ctrl/Shift,其它都无视
if (event->key() >= Qt::Key_A && event->key() <= Qt::Key_Z)
{
QChar strKey = (QChar)event->key()
if (event->modifiers() == Qt::ControlModifier)
{
this->setText(QString("CTRL+%0").arg(strKey))
}
else if (event->modifiers() == Qt::ShiftModifier)
{
this->setText(QString("SHIFT+%0").arg(strKey))
}
else if (event->modifiers() == (Qt::ShiftModifier | Qt::ControlModifier))
{
this->setText(QString("CTRL+SHIFT+%0").arg(strKey))
}
}
}
原文链接:https://blog.csdn.net/qq_36131739/article/details/100178232
很简单的程序,LZ自己写吧…… 大致如下: 首先自定义一个类,继承自QWIDGET,此类有QPUSHBUTTON,QLINEEDIT这两个子部件,再自定义一个槽函数,用来修改qlineedit中文本内容,再用个connect将qpushbutton的clicked()信号与自定义槽连接就可以了。欢迎分享,转载请注明来源:内存溢出
评论列表(0条)