问题描述
在stackoverflow.com网站的右上角有一个带有放大镜头和带有灰色搜索"关键字的搜索"字段:
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:
我想知道是否可以通过QLineEdit
获得相同的外观.如果是这样,怎么办?
I wonder if it is possible to achieve a same appearance with QLineEdit
. If so then how?
推荐答案
傻瓜的简单方法
- 添加
QLineEdit
,并通过QLineEdit::setFrame
将其设置为无框 - 添加具有白色背景颜色的
QLabel
(按样式表)和图标 - 合并行编辑和带有布局的标签,将间距设置为0
- 使用
QLineEdit::setPlaceholderText
设置占位符文本
- Add a
QLineEdit
, and set it frameless byQLine:setFrame
- Add a
QLabel
with background color in white (by stylesheet) and a icon - Combine the line edit and the label with a layout, set spacing to 0
- Set placeholder text with
QLine:setPlaceholderText
结果
检查此线程: "Can QLineEdit这样吗?"
Check this thread: "Can QLineEdit do this?"
和相关的python代码: http://bazaar.launchpad.net/~henning-schroeder/%2Bjunk/qtwidgets/annotate/head:/qtwidgets/lineedit.py
And the related python code: http://bazaar.launchpad.net/~henning-schroeder/%2Bjunk/qtwidgets/annotate/head:/qtwidgets/lineedit.py
或
如何做-内部在QLineEdit中插入按钮.[pyqt4]"
通过在其上绘制小部件(标签,按钮甚至组合框)来基本自定义QLineEdit
.然后重置边距,光标,填充和绘画事件.没有魔法!
Basically customized a QLineEdit
by painting a widget(label, button or even combobox) onto it. Then reset the margin, cursor, padding and the paint event. No magics!
这篇关于如何在QLineEdit上放置图标?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!