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// Qt-Security score:significant reason:default
4
6
7#include <QtGui/qevent.h>
8#include <QtWidgets/qmenu.h>
9
11
12using namespace Qt::StringLiterals;
13
14namespace qdesigner_internal {
15 PropertyLineEdit::PropertyLineEdit(QWidget *parent) :
16 QLineEdit(parent), m_wantNewLine(false)
17 {
18 }
19
20 bool PropertyLineEdit::event(QEvent *e)
21 {
22 // handle 'Select all' here as it is not done in the QLineEdit
23 if (e->type() == QEvent::ShortcutOverride && !isReadOnly()) {
24 QKeyEvent* ke = static_cast<QKeyEvent*> (e);
25 if (ke->modifiers() & Qt::ControlModifier) {
26 if(ke->key() == Qt::Key_A) {
27 ke->accept();
28 return true;
29 }
30 }
31 }
32 return QLineEdit::event(e);
33 }
34
35 void PropertyLineEdit::insertNewLine() {
36 insertText(u"\\n"_s);
37 }
38
39 void PropertyLineEdit::insertText(const QString &text) {
40 // position cursor after new text and grab focus
41 const int oldCursorPosition = cursorPosition ();
42 insert(text);
43 setCursorPosition (oldCursorPosition + text.size());
44 setFocus(Qt::OtherFocusReason);
45 }
46
47 void PropertyLineEdit::contextMenuEvent(QContextMenuEvent *event) {
48 QMenu *menu = createStandardContextMenu ();
49
50 if (m_wantNewLine) {
51 menu->addSeparator();
52 menu->addAction(tr("Insert line break"), this, &PropertyLineEdit::insertNewLine);
53 }
54
55 menu->exec(event->globalPos());
56 }
57}
58
59QT_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.