[英]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.