QT-设置QLineEdit无边框


QLineEdit *lineEdit = new QLineEdit();
lineEdit->setStyleSheet("QLineEdit{border-width:0;border-style:outset}");
在 PyQt ,如果你想让 `QLineEdit` 控件看起来没有边框,你可以使用 CSS 样式或者调整其样式属性来实现。以下是如何通过两种方法实现无边框: 1. **使用 CSS 样式**: 在 PyQt ,你可以使用 `setStyleSheet()` 方法为 `QLineEdit` 应用自定义样式。将边框宽度设置为0即可隐藏边框: ```python from PyQt5.QtWidgets import QApplication, QLineEdit from PyQt5.QtGui import QPalette app = QApplication([]) # 创建 QLineEdit line_edit = QLineEdit() # 设置边框样式 palette = QPalette() palette.setBrush(QPalette.Base, Qt.white) # 如果背景不是白色,需要设置背景色 palette.setBrush(QPalette.Text, Qt.black) line_edit.setPalette(palette) line_edit.setStyleSheet("QLineEdit {border: 0px; padding: 0px; background-color: transparent;}") line_edit.show() app.exec_() ``` 2. **直接修改样式属性**: 你也可以直接修改 `QLineEdit` 的样式属性,如边框宽度、边框类型等: ```python line_edit = QLineEdit() line_edit.setFrameShape(QFrame.NoFrame) # 设置边框框架形状 line_edit.setLineWidth(0) # 设置边框线宽度为0 # 其他设置,如背景透明度和字体颜色 line_edit.setAttribute(Qt.WA_TranslucentBackground, True) # 透明背景 line_edit.setStyleSheet("color: black;") line_edit.show() ``` 请注意,这两种方法可能会导致文本输入区域失去焦点时难以看到光标。如果你需要在失去焦点时显示一个虚线光标,可以考虑使用 `QLineEdit` 的 `showCursor` 方法。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值