// g++ rubber.cpp -o ss -lQtGui
#include <QtGui/QWidget>
#include <QtGui/QDesktopWidget>
#include <QtGui/QApplication>
#include <QtGui/QPixmap>
#include <QtGui/QRubberBand>
#include <QtGui/QMouseEvent>
#include <QtGui/QPushButton>
#include <QtGui/QFont>
#include <iostream>
using namespace std;
{
public:
protected:
};
MyWidget
::MyWidget(QWidget *parent
) {
setFixedSize(200, 120);
quit->setGeometry(62, 40, 75, 30);
connect(quit, SIGNAL(clicked()), qApp, SLOT(quit()));
}
int main(int argc, char *argv[])
{
/*
QPoint TopLeft(100,100);
QPoint BottomRight(200,200);
QRect SelectionRectangle(TopLeft, BottomRight);
QRubberBand outline (QRubberBand::Rectangle);
outline.setGeometry(SelectionRectangle);
outline.show();
*/
return MyScreenshot.exec();
}
{
cout << "Mouse moved!" << endl;
QRect SelectionRectangle
(TopLeft, BottomRight
);
outline.setGeometry(SelectionRectangle);
outline.show();
}
{
if (event->button() == Qt::LeftButton)
{
cout << "Left click!" << endl;
}
QRect SelectionRectangle
(TopLeft, BottomRight
);
outline.setGeometry(SelectionRectangle);
outline.show();
}
// g++ rubber.cpp -o ss -lQtGui
#include <QtGui/QWidget>
#include <QtGui/QDesktopWidget>
#include <QtGui/QApplication>
#include <QtGui/QPixmap>
#include <QtGui/QRubberBand>
#include <QtGui/QMouseEvent>
#include <QtGui/QPushButton>
#include <QtGui/QFont>
#include <iostream>
using namespace std;
class MyWidget : public QWidget
{
public:
MyWidget(QWidget *parent = 0);
protected:
void mouseMoveEvent( QMouseEvent * e);
void mousePressEvent(QMouseEvent *event);
};
MyWidget::MyWidget(QWidget *parent)
: QWidget(parent)
{
setFixedSize(200, 120);
QPushButton *quit = new QPushButton(tr("Quit"), this);
quit->setGeometry(62, 40, 75, 30);
connect(quit, SIGNAL(clicked()), qApp, SLOT(quit()));
}
int main(int argc, char *argv[])
{
QApplication MyScreenshot(argc,argv);
/*
QPoint TopLeft(100,100);
QPoint BottomRight(200,200);
QRect SelectionRectangle(TopLeft, BottomRight);
QRubberBand outline (QRubberBand::Rectangle);
outline.setGeometry(SelectionRectangle);
outline.show();
*/
return MyScreenshot.exec();
}
void MyWidget::mouseMoveEvent( QMouseEvent * e)
{
cout << "Mouse moved!" << endl;
QPoint TopLeft(100,100);
QPoint BottomRight(200,200);
QRect SelectionRectangle(TopLeft, BottomRight);
QRubberBand outline (QRubberBand::Rectangle);
outline.setGeometry(SelectionRectangle);
outline.show();
}
void MyWidget::mousePressEvent(QMouseEvent *event)
{
if (event->button() == Qt::LeftButton)
{
cout << "Left click!" << endl;
}
QPoint TopLeft(100,100);
QPoint BottomRight(200,200);
QRect SelectionRectangle(TopLeft, BottomRight);
QRubberBand outline (QRubberBand::Rectangle);
outline.setGeometry(SelectionRectangle);
outline.show();
}
To copy to clipboard, switch view to plain text mode
Bookmarks