文件中提到,
Qt Documentation
Qt 4.8 >QtGui >QFont
Public Functions
QFont()
QFont(const QString &family, int pointSize = -1, int weight = -1, bool italic = false)
QFont(const QFont &font, QPaintDevice * pd)
QFont(const QFont &font)
~QFont()
#ifndef MYWIDGET_H#define MYWIDGET_H
#include <QWidget>
#include <QtGui>
#include <QMouseEvent>
class MyWidget : public QWidget
{
public:
MyWidget()
void mousePressEvent(QMouseEvent *event)
void mouseMoveEvent(QMouseEvent *event)
void mouseReleaseEvent(QMouseEvent *event)
void paintEvent(QPaintEvent *event)
private:
QPoint m_PointStart
QPoint m_PointEnd
}
#endif // MYWIDGET_H
#include <QtGui/QApplication>
#include "mainwindow.h"
#include "mywidget.h"
int main(int argc, char *argv[])
{
QApplication a(argc, argv)
MyWidget widget
widget.show()
return a.exec()
}
#include "mywidget.h"
MyWidget::MyWidget()
{
resize(240,320)
}
void MyWidget::mousePressEvent(QMouseEvent *event)
{
m_PointStart = event->pos()
}
void MyWidget::mouseMoveEvent(QMouseEvent *event)
{
//m_PointEnd = event->pos()
//update()
}
void MyWidget::mouseReleaseEvent(QMouseEvent *event)
{
m_PointEnd = event->pos()
update()
}
void MyWidget::paintEvent(QPaintEvent *event)
{
QPainter painter(this)
painter.setBrush(QBrush(QColor(255,0,0)))
painter.drawPixmap(0,0,240,320,QPixmap("images/frame1.jpg"))
if(m_PointStart.x() < m_PointEnd.x())
painter.drawPixmap(0,0,240,320,QPixmap("images/frame2.jpg"))
else if(m_PointStart.x() > m_PointEnd.x())
painter.drawPixmap(0,0,240,320,QPixmap("images/frame3.jpg"))
}
在网上找到了一个很好的类子,一看就明白
转自:http://www.cppblog.com/qianqian/archive/2012/05/21/121418.html
窗口1 :Widget
namespace Ui {
class Widget
class Form
}
构造函数加入:connect(btn1,SIGNAL(clicked()),this,SLOT(open1()))
void Widget::open1()
{
this->hide()
w1 = new Form
w1->show()
connect(this->w1->f_ui->pushButton,SIGNAL(clicked()),this,SLOT(Display()))
}
void Widget::Display()
{
this->show()
w1->close()
}
窗口2 :
Form
#include "ui_form.h"
public:
Ui::Form *f_ui
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)