文章标题

QT

QWidget

paintEvent

mousePressEvent

void MyWidget::mousePressEvent(QMouseEvent *ev){
  _ptClicked = ev->pos();//QPoint _ptClicked;
  update();
}

QPainter

void MyWidget::paintEvent(QPaintEvent *){
    QPainter painter(this);

    painter.setPen(QColor(255,0,0));//red
    painter.setBrush(QBrush(QColor(255,255,0)));//yellow

    painter.drawLine(QPoint(0,0),QPoint(100,100));
    painter.drawText(100,100,"hhhhh");
    painter.drawEllipse(QPoint(200,200),30,30);
}

QPushButton

信号槽机制

//!!! Qt5
#include <QObject>
////////// newspaper.h
class Newspaper : public QObject
{
Q_OBJECT   //有了这个宏才能用信号槽机制
public:
Newspaper(const QString & name) :
m_name(name)
{
}
void send()
{
emit newPaper(m_name);//发送信号
}
signals:
void newPaper(const QString &name);
private:
QString m_name;
};
////////// reader.h
#include <QObject>
#include <QDebug>
class Reader : public QObject
{
Q_OBJECT
public:
Reader() {}
void receiveNewspaper(const QString & name)
{
qDebug() << "Receives Newspaper: " << name;
}
};
////////// main.cpp
#include <QCoreApplication>
#include "newspaper.h"
#include "reader.h"
int main(int argc, char *argv[])
{
QCoreApplication app(argc, argv);
Newspaper newspaper("Newspaper A");
Reader reader;
QObject::connect(&newspaper, &Newspaper::newPaper,
&reader, &Reader::receiveNewspaper);

newspaper.send();// 发送信号 槽接受 发生响应事件
return app.exec();
}
阅读更多
版权声明:本文为博主原创文章,未经博主允许不得转载。 https://blog.csdn.net/xuesheng229/article/details/46835459
文章标签: qtp
个人分类: markdown
下一篇vim
想对作者说点什么? 我来说一句

没有更多推荐了,返回首页

关闭
关闭