Try this, and see if it helps:
MainWindow
::MainWindow(QWidget *parent
) : ui(new Ui::MainWindow)
{
ui->setupUi(this);
//setAttribute(Qt::WA_NoMousePropagation, true); //you are on a top level widget!
//setAttribute(Qt::WA_NoMouseReplay, true); //what is this for here?
}
MainWindow::mousePressEvent(event); //if you want the normal behavior to stay
selection->move(event->pos());
selection->resize(1,1);
selection->show();
event->accept(); //why ignore? you are using the event! at any rate, since in this case you have no parents for the main windows, it doesn't really matter.
}
MainWindow::mouseMoveEvent(event);
qDebug()<<event->pos();
selection->resize(event->x()- selection->x(), event->y()- selection->y());
}
void MainWindow
::mouseReleaseEvent(QMouseEvent * event
){ MainWindow::mouseReleaseEvent(event);
selection->hide();
event->accept();
}
MainWindow::MainWindow(QWidget *parent) :
QMainWindow(parent),
ui(new Ui::MainWindow)
{
ui->setupUi(this);
selection=new QRubberBand(QRubberBand::Rectangle, this);
//setAttribute(Qt::WA_NoMousePropagation, true); //you are on a top level widget!
//setAttribute(Qt::WA_NoMouseReplay, true); //what is this for here?
}
void MainWindow::mousePressEvent(QMouseEvent * event){
MainWindow::mousePressEvent(event); //if you want the normal behavior to stay
selection->move(event->pos());
selection->resize(1,1);
selection->show();
event->accept(); //why ignore? you are using the event! at any rate, since in this case you have no parents for the main windows, it doesn't really matter.
}
void MainWindow::mouseMoveEvent(QMouseEvent * event){
MainWindow::mouseMoveEvent(event);
qDebug()<<event->pos();
selection->resize(event->x()- selection->x(), event->y()- selection->y());
}
void MainWindow::mouseReleaseEvent(QMouseEvent * event){
MainWindow::mouseReleaseEvent(event);
selection->hide();
event->accept();
}
To copy to clipboard, switch view to plain text mode
Bookmarks