Event QComboBox to Custom QLineEdit
The Problem: I have a custom event on QLineEdit inside a custom QComboBox and only specific events are being passed from QComboBox to QLineEdit when I want. I can't get tab to be passed.
I want when an event passed to QComboBox it will be passed to the QComboBox->lineEdit().
QCustomCombo::QCustomCombo():
m_lineEdit(new QCustomLineEdit)
setEditable(true);
setLineEdit(m_lineEdit);
bool QCustomCombo::event(QEvent * event)
if(event->type() == QEvent::KeyPress)
QKeyEvent * keyEvent = static_cast<QKeyEvent *>(event);
if(keyEvent->key() == Qt::Key_tab)
//pass to lineEdit();
//I have tried 'return true/false and QWidget::event(event)'
//I have also tried commenting out QCustomCombo::event, same problem
return QWidget::event(event);
QCustomLineEdit
bool QCustomLineEdit::event(QEvent * event)
if(event->type() == QEvent::KeyPress)
QKeyEvent * keyEvent = static_cast<QKeyEvent *>(event);
if(keyEvent->key() == Qt::Key_tab)
//Do custom Stuff
return true;
if(keyEvent->key() == Qt::Key_Right)
//Do custom Stuff
return true;
return QWidget::event(event);
The QLineEdit has a custom event for left and right arrow and tab. Only the arrows get passed. But I can't get the tab to pass to it.
c++ qt qt5 qcombobox qlineedit
add a comment |
The Problem: I have a custom event on QLineEdit inside a custom QComboBox and only specific events are being passed from QComboBox to QLineEdit when I want. I can't get tab to be passed.
I want when an event passed to QComboBox it will be passed to the QComboBox->lineEdit().
QCustomCombo::QCustomCombo():
m_lineEdit(new QCustomLineEdit)
setEditable(true);
setLineEdit(m_lineEdit);
bool QCustomCombo::event(QEvent * event)
if(event->type() == QEvent::KeyPress)
QKeyEvent * keyEvent = static_cast<QKeyEvent *>(event);
if(keyEvent->key() == Qt::Key_tab)
//pass to lineEdit();
//I have tried 'return true/false and QWidget::event(event)'
//I have also tried commenting out QCustomCombo::event, same problem
return QWidget::event(event);
QCustomLineEdit
bool QCustomLineEdit::event(QEvent * event)
if(event->type() == QEvent::KeyPress)
QKeyEvent * keyEvent = static_cast<QKeyEvent *>(event);
if(keyEvent->key() == Qt::Key_tab)
//Do custom Stuff
return true;
if(keyEvent->key() == Qt::Key_Right)
//Do custom Stuff
return true;
return QWidget::event(event);
The QLineEdit has a custom event for left and right arrow and tab. Only the arrows get passed. But I can't get the tab to pass to it.
c++ qt qt5 qcombobox qlineedit
add a comment |
The Problem: I have a custom event on QLineEdit inside a custom QComboBox and only specific events are being passed from QComboBox to QLineEdit when I want. I can't get tab to be passed.
I want when an event passed to QComboBox it will be passed to the QComboBox->lineEdit().
QCustomCombo::QCustomCombo():
m_lineEdit(new QCustomLineEdit)
setEditable(true);
setLineEdit(m_lineEdit);
bool QCustomCombo::event(QEvent * event)
if(event->type() == QEvent::KeyPress)
QKeyEvent * keyEvent = static_cast<QKeyEvent *>(event);
if(keyEvent->key() == Qt::Key_tab)
//pass to lineEdit();
//I have tried 'return true/false and QWidget::event(event)'
//I have also tried commenting out QCustomCombo::event, same problem
return QWidget::event(event);
QCustomLineEdit
bool QCustomLineEdit::event(QEvent * event)
if(event->type() == QEvent::KeyPress)
QKeyEvent * keyEvent = static_cast<QKeyEvent *>(event);
if(keyEvent->key() == Qt::Key_tab)
//Do custom Stuff
return true;
if(keyEvent->key() == Qt::Key_Right)
//Do custom Stuff
return true;
return QWidget::event(event);
The QLineEdit has a custom event for left and right arrow and tab. Only the arrows get passed. But I can't get the tab to pass to it.
c++ qt qt5 qcombobox qlineedit
The Problem: I have a custom event on QLineEdit inside a custom QComboBox and only specific events are being passed from QComboBox to QLineEdit when I want. I can't get tab to be passed.
I want when an event passed to QComboBox it will be passed to the QComboBox->lineEdit().
QCustomCombo::QCustomCombo():
m_lineEdit(new QCustomLineEdit)
setEditable(true);
setLineEdit(m_lineEdit);
bool QCustomCombo::event(QEvent * event)
if(event->type() == QEvent::KeyPress)
QKeyEvent * keyEvent = static_cast<QKeyEvent *>(event);
if(keyEvent->key() == Qt::Key_tab)
//pass to lineEdit();
//I have tried 'return true/false and QWidget::event(event)'
//I have also tried commenting out QCustomCombo::event, same problem
return QWidget::event(event);
QCustomLineEdit
bool QCustomLineEdit::event(QEvent * event)
if(event->type() == QEvent::KeyPress)
QKeyEvent * keyEvent = static_cast<QKeyEvent *>(event);
if(keyEvent->key() == Qt::Key_tab)
//Do custom Stuff
return true;
if(keyEvent->key() == Qt::Key_Right)
//Do custom Stuff
return true;
return QWidget::event(event);
The QLineEdit has a custom event for left and right arrow and tab. Only the arrows get passed. But I can't get the tab to pass to it.
c++ qt qt5 qcombobox qlineedit
c++ qt qt5 qcombobox qlineedit
edited Nov 14 '18 at 17:06
eyllanesc
79.2k103257
79.2k103257
asked Nov 14 '18 at 16:47
DevilGaleDevilGale
114
114
add a comment |
add a comment |
2 Answers
2
active
oldest
votes
Use QApplication::notify
bool QCustomCombo::event(QEvent * event)
if(event->type() == QEvent::KeyPress)
QKeyEvent * keyEvent = static_cast<QKeyEvent *>(event);
if(keyEvent->key() == Qt::Key_Tab)
qApp->notify(m_lineEdit, event);
return true;
return QWidget::event(event);
How do I get access to qApp functions? I triedQCustomCombo : private QApplication
, but that breaks myconnect()
lines. The QCombo is located inside a mainwindow.cpp created by a main.cpp (main.cpp is where I have QApplication instance).
– DevilGale
Nov 14 '18 at 21:41
@DevilGale it is not necessary to inherit, just include the header:#include <QApplication>
.QApplication::instance()
is a singleton that can be used with the qApp macro.
– eyllanesc
Nov 15 '18 at 2:07
add a comment |
I want when an event passed to QComboBox it will be passed to the
QComboBox->lineEdit().
installEventFilter() is your friend here. It allows object A to install an event filter on another object B, so that before object B's event(QEvent *)
method gets called, object A's eventFilter(QObject *, QEvent *)
method will be called first, so that object A can decide how to handle the event (and whether or not the event should be passed on to object B afterwards).
You can use that so that your CustomCombo
can see and react to events that would otherwise go directly to the `QComboBox.
add a comment |
Your Answer
StackExchange.ifUsing("editor", function ()
StackExchange.using("externalEditor", function ()
StackExchange.using("snippets", function ()
StackExchange.snippets.init();
);
);
, "code-snippets");
StackExchange.ready(function()
var channelOptions =
tags: "".split(" "),
id: "1"
;
initTagRenderer("".split(" "), "".split(" "), channelOptions);
StackExchange.using("externalEditor", function()
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled)
StackExchange.using("snippets", function()
createEditor();
);
else
createEditor();
);
function createEditor()
StackExchange.prepareEditor(
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader:
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
,
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
);
);
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53305074%2fevent-qcombobox-to-custom-qlineedit%23new-answer', 'question_page');
);
Post as a guest
Required, but never shown
2 Answers
2
active
oldest
votes
2 Answers
2
active
oldest
votes
active
oldest
votes
active
oldest
votes
Use QApplication::notify
bool QCustomCombo::event(QEvent * event)
if(event->type() == QEvent::KeyPress)
QKeyEvent * keyEvent = static_cast<QKeyEvent *>(event);
if(keyEvent->key() == Qt::Key_Tab)
qApp->notify(m_lineEdit, event);
return true;
return QWidget::event(event);
How do I get access to qApp functions? I triedQCustomCombo : private QApplication
, but that breaks myconnect()
lines. The QCombo is located inside a mainwindow.cpp created by a main.cpp (main.cpp is where I have QApplication instance).
– DevilGale
Nov 14 '18 at 21:41
@DevilGale it is not necessary to inherit, just include the header:#include <QApplication>
.QApplication::instance()
is a singleton that can be used with the qApp macro.
– eyllanesc
Nov 15 '18 at 2:07
add a comment |
Use QApplication::notify
bool QCustomCombo::event(QEvent * event)
if(event->type() == QEvent::KeyPress)
QKeyEvent * keyEvent = static_cast<QKeyEvent *>(event);
if(keyEvent->key() == Qt::Key_Tab)
qApp->notify(m_lineEdit, event);
return true;
return QWidget::event(event);
How do I get access to qApp functions? I triedQCustomCombo : private QApplication
, but that breaks myconnect()
lines. The QCombo is located inside a mainwindow.cpp created by a main.cpp (main.cpp is where I have QApplication instance).
– DevilGale
Nov 14 '18 at 21:41
@DevilGale it is not necessary to inherit, just include the header:#include <QApplication>
.QApplication::instance()
is a singleton that can be used with the qApp macro.
– eyllanesc
Nov 15 '18 at 2:07
add a comment |
Use QApplication::notify
bool QCustomCombo::event(QEvent * event)
if(event->type() == QEvent::KeyPress)
QKeyEvent * keyEvent = static_cast<QKeyEvent *>(event);
if(keyEvent->key() == Qt::Key_Tab)
qApp->notify(m_lineEdit, event);
return true;
return QWidget::event(event);
Use QApplication::notify
bool QCustomCombo::event(QEvent * event)
if(event->type() == QEvent::KeyPress)
QKeyEvent * keyEvent = static_cast<QKeyEvent *>(event);
if(keyEvent->key() == Qt::Key_Tab)
qApp->notify(m_lineEdit, event);
return true;
return QWidget::event(event);
answered Nov 14 '18 at 20:46
Serhiy KulishSerhiy Kulish
1524
1524
How do I get access to qApp functions? I triedQCustomCombo : private QApplication
, but that breaks myconnect()
lines. The QCombo is located inside a mainwindow.cpp created by a main.cpp (main.cpp is where I have QApplication instance).
– DevilGale
Nov 14 '18 at 21:41
@DevilGale it is not necessary to inherit, just include the header:#include <QApplication>
.QApplication::instance()
is a singleton that can be used with the qApp macro.
– eyllanesc
Nov 15 '18 at 2:07
add a comment |
How do I get access to qApp functions? I triedQCustomCombo : private QApplication
, but that breaks myconnect()
lines. The QCombo is located inside a mainwindow.cpp created by a main.cpp (main.cpp is where I have QApplication instance).
– DevilGale
Nov 14 '18 at 21:41
@DevilGale it is not necessary to inherit, just include the header:#include <QApplication>
.QApplication::instance()
is a singleton that can be used with the qApp macro.
– eyllanesc
Nov 15 '18 at 2:07
How do I get access to qApp functions? I tried
QCustomCombo : private QApplication
, but that breaks my connect()
lines. The QCombo is located inside a mainwindow.cpp created by a main.cpp (main.cpp is where I have QApplication instance).– DevilGale
Nov 14 '18 at 21:41
How do I get access to qApp functions? I tried
QCustomCombo : private QApplication
, but that breaks my connect()
lines. The QCombo is located inside a mainwindow.cpp created by a main.cpp (main.cpp is where I have QApplication instance).– DevilGale
Nov 14 '18 at 21:41
@DevilGale it is not necessary to inherit, just include the header:
#include <QApplication>
. QApplication::instance()
is a singleton that can be used with the qApp macro.– eyllanesc
Nov 15 '18 at 2:07
@DevilGale it is not necessary to inherit, just include the header:
#include <QApplication>
. QApplication::instance()
is a singleton that can be used with the qApp macro.– eyllanesc
Nov 15 '18 at 2:07
add a comment |
I want when an event passed to QComboBox it will be passed to the
QComboBox->lineEdit().
installEventFilter() is your friend here. It allows object A to install an event filter on another object B, so that before object B's event(QEvent *)
method gets called, object A's eventFilter(QObject *, QEvent *)
method will be called first, so that object A can decide how to handle the event (and whether or not the event should be passed on to object B afterwards).
You can use that so that your CustomCombo
can see and react to events that would otherwise go directly to the `QComboBox.
add a comment |
I want when an event passed to QComboBox it will be passed to the
QComboBox->lineEdit().
installEventFilter() is your friend here. It allows object A to install an event filter on another object B, so that before object B's event(QEvent *)
method gets called, object A's eventFilter(QObject *, QEvent *)
method will be called first, so that object A can decide how to handle the event (and whether or not the event should be passed on to object B afterwards).
You can use that so that your CustomCombo
can see and react to events that would otherwise go directly to the `QComboBox.
add a comment |
I want when an event passed to QComboBox it will be passed to the
QComboBox->lineEdit().
installEventFilter() is your friend here. It allows object A to install an event filter on another object B, so that before object B's event(QEvent *)
method gets called, object A's eventFilter(QObject *, QEvent *)
method will be called first, so that object A can decide how to handle the event (and whether or not the event should be passed on to object B afterwards).
You can use that so that your CustomCombo
can see and react to events that would otherwise go directly to the `QComboBox.
I want when an event passed to QComboBox it will be passed to the
QComboBox->lineEdit().
installEventFilter() is your friend here. It allows object A to install an event filter on another object B, so that before object B's event(QEvent *)
method gets called, object A's eventFilter(QObject *, QEvent *)
method will be called first, so that object A can decide how to handle the event (and whether or not the event should be passed on to object B afterwards).
You can use that so that your CustomCombo
can see and react to events that would otherwise go directly to the `QComboBox.
answered Nov 15 '18 at 1:56
Jeremy FriesnerJeremy Friesner
39.5k1080162
39.5k1080162
add a comment |
add a comment |
Thanks for contributing an answer to Stack Overflow!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53305074%2fevent-qcombobox-to-custom-qlineedit%23new-answer', 'question_page');
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown