[英]Qt4: Making fullscreen window impossible to get around (a lock screen)?
[英]Qt4: Decorating a QLineEdit (painting around it)
我试图“装饰”一个QLineEdit
,或更准确地说,是在它周围绘制我自己的自定义框架,以获得以下结果:
我尝试使用Qt样式表 (CSS),但这只会启用琐碎的框架装饰(更改宽度/颜色/大小等),没有像上面这样的幻想。
我还尝试了从QLineEdit
继承并覆盖其void QLineEdit::paintEvent(QPaintEvent* e)
,但是后来我意识到重新实现它意味着我将失去QLineEdit
的“编辑性”(抱歉,在此处使用这种语言)-文本框,光标,以及插入文本的功能。
如何实现上述文本框?
这是QLabel
完美结合,位于QLineEdit
后面吗?
尝试使用合成物。 创建自己的Widget,它继承自QWidget
,在QWidget::paintEvent
绘制所需的内容,并将QLineEdit
放在其上方。 可能您必须将其居中并使用css
进行QLineEdit
使其看起来平滑。
class MyWidget: public QWidget
{
explicit MyWidget(QWidget* parent = 0):
QWidget(parent),
line_edit(new QLineEdit(this))
{
// place line_edit in center of QWidget
}
private:
QLineEdit* line_edit;
}
或者您可以像这样重写void QLineEdit::paintEvent(QPaintEvent* e)
void QLineEdit::paintEvent(QPaintEvent* e)
{
//paint your border
QLineEdit::paintEvent(e);
}
而且您不会失去QLineEdits
“编辑性”。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.