NullPointer
14th August 2011, 00:31
Hi,
I'm learning to use QRubberBand, so I created a app with a QMainWindow and now I'm reimplementing the three mouse events to make possible to "select" a space using the rubber band...
Everything runs great, except that I have to "double click" or use a modifier to allow the mouseMoveEvent get caught correctly. I'm under KDE 4.5.5, and it have that thing of moving the windows when you drag a widget from anywhere...
I have tried the grabMouse, WA_NoMousePropagation, WA_NoMouseReplay, event->ignore() and event->accept, but nothing solved this issue...
My code is:
#include "mainwindow.h"
#include "ui_mainwindow.h"
#include <QRubberBand>
#include <QMouseEvent>
#include <QDebug>
MainWindow::MainWindow(QWidget *parent) :
QMainWindow(parent),
ui(new Ui::MainWindow)
{
ui->setupUi(this);
selection=new QRubberBand(QRubberBand::Rectangle, this);
setAttribute(Qt::WA_NoMousePropagation, true);
setAttribute(Qt::WA_NoMouseReplay, true);
}
MainWindow::~MainWindow()
{
delete ui;
}
void MainWindow::mousePressEvent(QMouseEvent * event){
//grabMouse();
releaseMouse();
selection->move(event->pos());
selection->resize(1,1);
selection->show();
event->ignore();
}
void MainWindow::mouseMoveEvent(QMouseEvent * event){
qDebug()<<event->pos();
selection->resize(event->x()- selection->x(), event->y()- selection->y());
}
void MainWindow::mouseReleaseEvent(QMouseEvent * event){
selection->hide();
//releaseMouse();
}
With the debug, I noticed that not always the event is called, just when I double click or use modifiers (ctrl, alt or shift) ...
How can I solve this?
I'm learning to use QRubberBand, so I created a app with a QMainWindow and now I'm reimplementing the three mouse events to make possible to "select" a space using the rubber band...
Everything runs great, except that I have to "double click" or use a modifier to allow the mouseMoveEvent get caught correctly. I'm under KDE 4.5.5, and it have that thing of moving the windows when you drag a widget from anywhere...
I have tried the grabMouse, WA_NoMousePropagation, WA_NoMouseReplay, event->ignore() and event->accept, but nothing solved this issue...
My code is:
#include "mainwindow.h"
#include "ui_mainwindow.h"
#include <QRubberBand>
#include <QMouseEvent>
#include <QDebug>
MainWindow::MainWindow(QWidget *parent) :
QMainWindow(parent),
ui(new Ui::MainWindow)
{
ui->setupUi(this);
selection=new QRubberBand(QRubberBand::Rectangle, this);
setAttribute(Qt::WA_NoMousePropagation, true);
setAttribute(Qt::WA_NoMouseReplay, true);
}
MainWindow::~MainWindow()
{
delete ui;
}
void MainWindow::mousePressEvent(QMouseEvent * event){
//grabMouse();
releaseMouse();
selection->move(event->pos());
selection->resize(1,1);
selection->show();
event->ignore();
}
void MainWindow::mouseMoveEvent(QMouseEvent * event){
qDebug()<<event->pos();
selection->resize(event->x()- selection->x(), event->y()- selection->y());
}
void MainWindow::mouseReleaseEvent(QMouseEvent * event){
selection->hide();
//releaseMouse();
}
With the debug, I noticed that not always the event is called, just when I double click or use modifiers (ctrl, alt or shift) ...
How can I solve this?