View Full Version : Alt + click for a QWidget

30th April 2008, 07:51
I'd like to be able to catch the alt + click event in my custom widget, but it seems that that event is used by the top level window to be able to move the window around the desktop.

Is it possible for the top level window to ignore the alt+click event? Maybe I didn't look hard enough, but I couldn't find a solution in the documentation. Does anyone know a solution, or give a hint in what direction I should look?

The following code illustrates my problem, except for the alt modifier key all other modifier keys can be caught.

#include <QtGui>
class Widget : public QWidget {
Widget() : QWidget(){}
void mousePressEvent(QMouseEvent *me) {
if (me->modifiers() & Qt::AltModifier) {
qDebug("Alt + click");
} else if (me->modifiers() & Qt::ControlModifier) {
qDebug("Control + click");
} else if (me->modifiers() & Qt::ShiftModifier) {
qDebug("Shift + click");
} else if (me->modifiers() & Qt::MetaModifier) {
qDebug("Meta + click");
} else {

int main(int argc, char **argv)
QApplication app(argc, argv);
Widget w;
return app.exec();

30th April 2008, 18:31
You need that something happen on the QWidget when you press ALT + CLICK?

1st May 2008, 02:37
On many unix desktops, ALT+Left Click Drag moves the window around. THis is handled by the window manager and as far as I know there is no way for you to get around this. Use a different modifier key instead, or provide an alternate way to accomplish this task for those users.