资源简介
QGraphicsView用来显示一个滚动视图区的QGraphicsScene内容。QGraphicsScene提供了QGraphicsItem的容器功能。通常与QGraphicsView一起使用来描述可视化图形项目。
QGraphicsScene提供了一个视图的场景,通过在这样一个场景之上加入不同的QGraphicsItem来构建视图。而QGraphicsView则提供了一个widget来显示QGraphicsScene的内容。所以要想成功构建一个视图,这三个元素缺一不可。
以下是一个QGraphicsView的例子,实现滑动的窗体效果,工具栏和图片均为场景中的Item。
代码片段和文件信息
/****************************************************************************
**
** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies).
** Contact: Qt Software Information (qt-info@nokia.com)
**
** This file is part of the Graphics Dojo project on Qt Labs.
**
** This file may be used under the terms of the GNU General Public
** License version 2.0 or 3.0 as published by the Free Software Foundation
** and appearing in the file LICENSE.GPL included in the packaging of
** this file. Please review the following information to ensure GNU
** General Public Licensing requirements will be met:
** http://www.fsf.org/licensing/licenses/info/GPLv2.html and
** http://www.gnu.org/copyleft/gpl.html.
**
** If you are unsure which license is appropriate for your use please
** contact the sales department at qt-sales@nokia.com.
**
** This file is provided AS IS with NO WARRANTY OF ANY KIND INCLUDING THE
** WARRANTY OF DESIGN MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
**
****************************************************************************/
#include
#include
#include
#if defined (Q_OS_SYMBIAN)
#include “sym_iap_util.h“
#include
#include
#include
#include
#endif
#define PAGE_COUNT 5
class NaviBar : public Qobject public QGraphicsRectItem
{
Q_object
public:
NaviBar();
void setPageOffset(qreal ofs);
signals:
void pageSelected(int page);
protected:
void mousePressEvent(QGraphicsSceneMouseEvent *event);
void paint(QPainter *painter const QstyleOptionGraphicsItem *option QWidget *widget = 0);
private:
QList m_icons;
QGraphicsRectItem *m_cursor;
};
#define ICON_SIZE 50
#define ICON_PAD 4
NaviBar::NaviBar()
: QGraphicsRectItem()
{
setRect(0 0 5 * ICON_SIZE ICON_SIZE);
setPen(Qt::NoPen);
QStringList names;
names << “map“ << “web“ << “home“ << “weather“ << “contacts“;
for (int i = 0; i < names.count(); ++i) {
QString fname = names[i];
fname.prepend(“:/icons/“);
fname.append(“-page.svg“);
QGraphicsSvgItem *icon = new QGraphicsSvgItem(fname);
icon->setParentItem(this);
const int dim = ICON_SIZE - ICON_PAD * 2;
qreal sw = dim / icon->boundingRect().width();
qreal sh = dim / icon->boundingRect().height();
icon->setTransform(QTransform().scale(sw sh));
icon->setZValue(2);
m_icons << icon;
}
m_cursor = new QGraphicsRectItem;
m_cursor->setParentItem(this);
m_cursor->setRect(0 0 ICON_SIZE ICON_SIZE);
m_cursor->setZValue(1);
m_cursor->setPen(Qt::NoPen);
m_cursor->setBrush(QColor(Qt::white));
m_cursor->setOpacity(0.6);
}
void NaviBar::setPageOffset(qreal ofs)
{
m_cursor->setPos(ofs * ICON_SIZE 0);
for (int i = 0; i < m_icons.count(); ++i) {
int y = (i == static_cast(ofs + 0.5)) ? ICON_PAD : ICON_PAD * 2;
m_icons[i]->setPos(i *
属性 大小 日期 时间 名称
----------- --------- ---------- ----- ----
目录 0 2010-07-24 12:15 parallaxhome\
目录 0 2010-07-24 12:14 parallaxhome\icons\
文件 28205 2009-11-29 09:37 parallaxhome\icons\contacts-page.svg
文件 1200 2009-11-29 09:37 parallaxhome\icons\go-back.png
文件 1219 2009-11-29 09:37 parallaxhome\icons\go-forward.png
文件 21437 2009-11-29 09:37 parallaxhome\icons\home-page.svg
文件 19750 2009-11-29 09:37 parallaxhome\icons\image-page.svg
文件 20393 2009-11-29 09:37 parallaxhome\icons\map-page.svg
文件 1628 2009-11-29 09:37 parallaxhome\icons\options-menu.png
文件 79 2009-11-29 09:37 parallaxhome\icons\README.txt
文件 38120 2009-11-29 09:37 parallaxhome\icons\surfacing.jpg
文件 502912 2009-11-29 09:37 parallaxhome\icons\surfacing.png
文件 44607 2009-11-29 09:37 parallaxhome\icons\weather-page.svg
文件 31559 2009-11-29 09:37 parallaxhome\icons\web-page.svg
目录 0 2010-07-24 12:14 parallaxhome\images\
文件 10920 2009-11-29 09:37 parallaxhome\images\brownies.jpg
文件 6537 2009-11-29 09:37 parallaxhome\images\chocolate.jpg
文件 12103 2009-11-29 09:37 parallaxhome\images\cookies.jpg
文件 12227 2009-11-29 09:37 parallaxhome\images\fish.jpg
文件 7342 2009-11-29 09:37 parallaxhome\images\mussels.jpg
文件 9670 2009-11-29 09:37 parallaxhome\images\pasta.jpg
文件 10769 2009-11-29 09:37 parallaxhome\images\pizza.jpg
文件 8676 2009-11-29 09:37 parallaxhome\images\puding.jpg
文件 9431 2009-11-29 09:37 parallaxhome\images\sushi.jpg
文件 12022 2009-11-29 09:37 parallaxhome\images\trouts.jpg
文件 8496 2009-11-29 09:37 parallaxhome\parallaxhome.cpp
文件 81 2009-11-29 09:37 parallaxhome\parallaxhome.pro
文件 701 2009-11-29 09:37 parallaxhome\parallaxhome.qrc
- 上一篇:ad7606使用说明.docx
- 下一篇:各个行业的ERP设计ER图
评论
共有 条评论