当前位置: 技术问答>linux和unix
QT关于滚动条的问题,大家一定要看啊,帮帮我啊!
来源: 互联网 发布时间:2015-10-19
本文导语: 我在Qt中写了一个类,用于显示一个Jpeg图像,要求用滚动条,我也做出来了,不过刷新太慢,我用鼠标拖动滚动条时,反应很迟钝,过一会儿才刷新过来,而且屏幕老在闪,请大家给我指点一下,我现在想找问题都不...
我在Qt中写了一个类,用于显示一个Jpeg图像,要求用滚动条,我也做出来了,不过刷新太慢,我用鼠标拖动滚动条时,反应很迟钝,过一会儿才刷新过来,而且屏幕老在闪,请大家给我指点一下,我现在想找问题都不知道从哪下手!我的类如下所示:
--------------------------------
这是imageView.h文件
------------------------------
#include
#include
class QPainter;
class QPaintEvent;
class CImageView : public QScrollView
{
Q_OBJECT
public:
CImageView(QWidget* parent, const char* name = 0);
void setImage(const QImage &newimage);
protected:
void drawContents(QPainter *painter, int x, int y, int width, int height);
public slots:
void paintEvent(QPaintEvent *);
private:
void resizeContents();
QImage *image;
};
----------------------------------------
这是imageView.cpp文件
---------------------------------------
#include
#include
#include
#include
#include "imageView.h"
CImageView::CImageView(QWidget* parent, const char *name)
: QScrollView(parent, name, WStaticContents)
{
image = new QImage();
}
void CImageView::setImage(const QImage &newimage)
{
*image = newimage;
resizeContents();
updateContents();
}
void CImageView::resizeContents()
{
QSize size = image->size();
QScrollView::resizeContents(size.width(), size.height());
}
void CImageView::drawContents(QPainter* painter, int , int , int, int)
{
QSize size = image->size();
painter->drawImage(QRect(0,0,size.width(), size.height()), *image);
}
void CImageView::paintEvent(QPaintEvent *)
{
}
----------------------------------------------------------------------
下面是的调用
-------------------------------------
CImageView *imageView
imageView = new CImageView(this);
imageView->setGeometry(QRect(20,20,180,180));
imageView->setImage(*image)//image指向一个文件
QPainter p;
p.begin(imageView);
p.end();
请大家一定要帮帮我啊,我真的很着急的!
--------------------------------
这是imageView.h文件
------------------------------
#include
#include
class QPainter;
class QPaintEvent;
class CImageView : public QScrollView
{
Q_OBJECT
public:
CImageView(QWidget* parent, const char* name = 0);
void setImage(const QImage &newimage);
protected:
void drawContents(QPainter *painter, int x, int y, int width, int height);
public slots:
void paintEvent(QPaintEvent *);
private:
void resizeContents();
QImage *image;
};
----------------------------------------
这是imageView.cpp文件
---------------------------------------
#include
#include
#include
#include
#include "imageView.h"
CImageView::CImageView(QWidget* parent, const char *name)
: QScrollView(parent, name, WStaticContents)
{
image = new QImage();
}
void CImageView::setImage(const QImage &newimage)
{
*image = newimage;
resizeContents();
updateContents();
}
void CImageView::resizeContents()
{
QSize size = image->size();
QScrollView::resizeContents(size.width(), size.height());
}
void CImageView::drawContents(QPainter* painter, int , int , int, int)
{
QSize size = image->size();
painter->drawImage(QRect(0,0,size.width(), size.height()), *image);
}
void CImageView::paintEvent(QPaintEvent *)
{
}
----------------------------------------------------------------------
下面是的调用
-------------------------------------
CImageView *imageView
imageView = new CImageView(this);
imageView->setGeometry(QRect(20,20,180,180));
imageView->setImage(*image)//image指向一个文件
QPainter p;
p.begin(imageView);
p.end();
请大家一定要帮帮我啊,我真的很着急的!
|
拖动时,有一部分图像是不用重画的,内存传送过去就行了,只画原来未显示的那些