Qt
Internal/Contributor docs for the Qt SDK. Note: These are NOT official API docs; those are found at https://doc.qt.io/
Loading...
Searching...
No Matches
propertylineedit.cpp
Go to the documentation of this file.
1// Copyright (C) 2016 The Qt Company Ltd.
2// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only WITH Qt-GPL-exception-1.0
3
5
6#include <QtGui/qevent.h>
7#include <QtWidgets/qmenu.h>
8
10
11using namespace Qt::StringLiterals;
12
13namespace qdesigner_internal {
14 PropertyLineEdit::PropertyLineEdit(QWidget *parent) :
15 QLineEdit(parent), m_wantNewLine(false)
16 {
17 }
18
19 bool PropertyLineEdit::event(QEvent *e)
20 {
21 // handle 'Select all' here as it is not done in the QLineEdit
22 if (e->type() == QEvent::ShortcutOverride && !isReadOnly()) {
23 QKeyEvent* ke = static_cast<QKeyEvent*> (e);
24 if (ke->modifiers() & Qt::ControlModifier) {
25 if(ke->key() == Qt::Key_A) {
26 ke->accept();
27 return true;
28 }
29 }
30 }
31 return QLineEdit::event(e);
32 }
33
34 void PropertyLineEdit::insertNewLine() {
35 insertText(u"\\n"_s);
36 }
37
38 void PropertyLineEdit::insertText(const QString &text) {
39 // position cursor after new text and grab focus
40 const int oldCursorPosition = cursorPosition ();
41 insert(text);
42 setCursorPosition (oldCursorPosition + text.size());
43 setFocus(Qt::OtherFocusReason);
44 }
45
46 void PropertyLineEdit::contextMenuEvent(QContextMenuEvent *event) {
47 QMenu *menu = createStandardContextMenu ();
48
49 if (m_wantNewLine) {
50 menu->addSeparator();
51 menu->addAction(tr("Insert line break"), this, &PropertyLineEdit::insertNewLine);
52 }
53
54 menu->exec(event->globalPos());
55 }
56}
57
58QT_END_NAMESPACE
void contextMenuEvent(QContextMenuEvent *event) override
This event handler, for event event, can be reimplemented in a subclass to receive widget context men...
bool event(QEvent *e) override
This virtual function receives events to an object and should return true if the event e was recogniz...
Combined button and popup list for selecting options.
Auxiliary methods to store/retrieve settings.