本文介绍了如何在QLineEdit上放置图标?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

限时删除!!

在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?

推荐答案

傻瓜的简单方法

  1. 添加QLineEdit,并通过QLineEdit::setFrame
  2. 将其设置为无框
  3. 添加具有白色背景颜色的QLabel(按样式表)和图标
  4. 合并行编辑和带有布局的标签,将间距设置为0
  5. 使用QLineEdit::setPlaceholderText
  6. 设置占位符文本
  1. Add a QLineEdit, and set it frameless by QLine:setFrame
  2. Add a QLabel with background color in white (by stylesheet) and a icon
  3. Combine the line edit and the label with a layout, set spacing to 0
  4. 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上放置图标?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

1403页,肝出来的..

09-08 11:15