Qt-interest Archive, February 2007
QComboBox->lineEdit context menu problem
Message 1 in thread
Hi There,
I am back to the Qt GUI magic again. My specification says that I need to
delete items from an editable combo box (in my case a QComboBox) on right
mouse click. That simple thing started to look overly complicated to me.
First I tried with overriding ::mouseReleaseEvent and ::mousePressEvent.
That did not manage to block the flow of course. Then I continued with
installing an event handler in my GUI class derived from QMainWindow like
this:
bool CTester::eventFilter(QObject *pObject, QEvent *pEvent) {
int i;
for (i = 0; i < LayoutItems.size(); i++) {
if (pObject ==
LayoutItems.at(i).pComboBoxValues->lineEdit()) {
if (pEvent->type() == QEvent::MouseButtonPress ||
pEvent->type() == QEvent::MouseButtonRelease) {
QMouseEvent *pMouseEvent =
static_cast<QMouseEvent*>(pEvent);
if (pMouseEvent->button() ==
Qt::RightButton) {
// pEvent->accept();
return true;
}
}
break;
}
}
return false;
}
This does not work, I got still the menu. Then I looked into how else...
There should be an easier way to do it such as a flag or so, I cannot
believe that I should subclass both QComboBox and QLineEdit to achieve
this... I need chocolate.
Cheers,
Sandor
Message 2 in thread
And I still get the contextmenu after using:
LayoutItem.at(i).pComboBoxValues->lineEdit()->setContextMenuPolicy(Qt::NoCon
textMenu);
I wonder why...
-----Original Message-----
From: Hadas Sandor [mailto:Sandor.Hadas@xxxxxxxx]
Sent: 22/02/2007 15:45
To: 'qt-interest@xxxxxxxxxxxxx'
Subject: QComboBox->lineEdit context menu problem
Hi There,
I am back to the Qt GUI magic again. My specification says that I need to
delete items from an editable combo box (in my case a QComboBox) on right
mouse click. That simple thing started to look overly complicated to me.
First I tried with overriding ::mouseReleaseEvent and ::mousePressEvent.
That did not manage to block the flow of course. Then I continued with
installing an event handler in my GUI class derived from QMainWindow like
this:
bool CTester::eventFilter(QObject *pObject, QEvent *pEvent) {
int i;
for (i = 0; i < LayoutItems.size(); i++) {
if (pObject ==
LayoutItems.at(i).pComboBoxValues->lineEdit()) {
if (pEvent->type() == QEvent::MouseButtonPress ||
pEvent->type() == QEvent::MouseButtonRelease) {
QMouseEvent *pMouseEvent =
static_cast<QMouseEvent*>(pEvent);
if (pMouseEvent->button() ==
Qt::RightButton) {
// pEvent->accept();
return true;
}
}
break;
}
}
return false;
}
This does not work, I got still the menu. Then I looked into how else...
There should be an easier way to do it such as a flag or so, I cannot
believe that I should subclass both QComboBox and QLineEdit to achieve
this... I need chocolate.
Cheers,
Sandor
Message 3 in thread
Too much mailing from me :) Got it:
bool CKmpTester::eventFilter(QObject *pObject, QEvent *pEvent) {
if (pEvent->type() == QEvent::ContextMenu) {
return true;
}
}
-----Original Message-----
From: Hadas Sandor
Sent: 22/02/2007 15:51
To: Hadas Sandor; 'qt-interest@xxxxxxxxxxxxx'
Subject: RE: QComboBox->lineEdit context menu problem
And I still get the contextmenu after using:
LayoutItem.at(i).pComboBoxValues->lineEdit()->setContextMenuPolicy(Qt::NoCon
textMenu);
I wonder why...
-----Original Message-----
From: Hadas Sandor [mailto:Sandor.Hadas@xxxxxxxx]
Sent: 22/02/2007 15:45
To: 'qt-interest@xxxxxxxxxxxxx'
Subject: QComboBox->lineEdit context menu problem
Hi There,
I am back to the Qt GUI magic again. My specification says that I need to
delete items from an editable combo box (in my case a QComboBox) on right
mouse click. That simple thing started to look overly complicated to me.
First I tried with overriding ::mouseReleaseEvent and ::mousePressEvent.
That did not manage to block the flow of course. Then I continued with
installing an event handler in my GUI class derived from QMainWindow like
this:
bool CTester::eventFilter(QObject *pObject, QEvent *pEvent) {
int i;
for (i = 0; i < LayoutItems.size(); i++) {
if (pObject ==
LayoutItems.at(i).pComboBoxValues->lineEdit()) {
if (pEvent->type() == QEvent::MouseButtonPress ||
pEvent->type() == QEvent::MouseButtonRelease) {
QMouseEvent *pMouseEvent =
static_cast<QMouseEvent*>(pEvent);
if (pMouseEvent->button() ==
Qt::RightButton) {
// pEvent->accept();
return true;
}
}
break;
}
}
return false;
}
This does not work, I got still the menu. Then I looked into how else...
There should be an easier way to do it such as a flag or so, I cannot
believe that I should subclass both QComboBox and QLineEdit to achieve
this... I need chocolate.
Cheers,
Sandor