16,213
社区成员
发帖
与我相关
我的任务
分享
class MyLabel:public QLabel
{
public:
void mousePressEvent(QMouseEvent *ev);
};
void MyLabel::mousePressEvent(QMouseEvent *ev)
{
//QMessageBox::information(NULL,"USE","Now Working!");
this->setText(QString("<center><h1>Move: (%1, %2)</h1></center>")
.arg(QString::number(ev->x()), QString::number(ev->y())));
}
class mWindow:public QMainWindow
{
private:
MyLabel *mlabel;
QPushButton *pButton;
protected:
void mousePressEvent(QMouseEvent *ev){
this->mlabel->mousePressEvent(ev);
}
public:
mWindow(QWidget *parent=0):QMainWindow(parent){
mlabel=new MyLabel;
mlabel->setText("hello");
pButton=new QPushButton;
pButton->setText("Hello");
QHBoxLayout a;
QToolBar *tool=this->addToolBar("D");
tool->addWidget(pButton);
this->statusBar()->addWidget(mlabel);
}
};
int main(int argc, char *argv[])
{
QApplication a(argc, argv);
mWindow w;
w.show();
return a.exec();
}