Try this, and see if it helps:
Qt Code:
  1. MainWindow::MainWindow(QWidget *parent) :
  2. QMainWindow(parent),
  3. ui(new Ui::MainWindow)
  4. {
  5. ui->setupUi(this);
  6. selection=new QRubberBand(QRubberBand::Rectangle, this);
  7. //setAttribute(Qt::WA_NoMousePropagation, true); //you are on a top level widget!
  8. //setAttribute(Qt::WA_NoMouseReplay, true); //what is this for here?
  9. }
  10.  
  11. void MainWindow::mousePressEvent(QMouseEvent * event){
  12. MainWindow::mousePressEvent(event); //if you want the normal behavior to stay
  13. selection->move(event->pos());
  14. selection->resize(1,1);
  15. selection->show();
  16. 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.
  17. }
  18.  
  19. void MainWindow::mouseMoveEvent(QMouseEvent * event){
  20. MainWindow::mouseMoveEvent(event);
  21. qDebug()<<event->pos();
  22. selection->resize(event->x()- selection->x(), event->y()- selection->y());
  23. }
  24.  
  25. void MainWindow::mouseReleaseEvent(QMouseEvent * event){
  26. MainWindow::mouseReleaseEvent(event);
  27. selection->hide();
  28. event->accept();
  29. }
To copy to clipboard, switch view to plain text mode