<1>. 头文件(类声明)

class CPreviewWidge : public QWidget
{
Q_OBJECT
public:
CPreviewWidge( const QString &strPath, QWidget *parent = );
~CPreviewWidge(); QSize sizeHint()const; protected:
void paintEvent(QPaintEvent *e); //九宫图重绘函数 private:
QImage m_imgLTop;        //九宫图图片左上
QImage m_imgLCur;        //九宫图图片左中
QImage m_imgLBut;        //九宫图图片左下 QImage m_imgCTop;        //九宫图图片中上
QImage m_imgCCur;        //九宫图图片中中
QImage m_imgCBut;        //九宫图图片中下 QImage m_imgRTop;        //九宫图图片右上
QImage m_imgRCur;        //九宫图图片右中
QImage m_imgRBut;        //九宫图图片右下
};

<2>. cpp文件(类定义)

CPreviewWidge::CPreviewWidge( const QString &strPath, QWidget *parent )    //传参:九宫图中上图片路径和控件父类对象
: QWidget( parent )
{
int iLeft = strPath.lastIndexOf( "_" );
QString strLeftPath = strPath.left( iLeft ); m_imgLTop = QImage( strLeftPath + "_ltop.png" );
m_imgLCur = QImage( strLeftPath + "_lcur.png" );
m_imgLBut = QImage( strLeftPath + "_lbot.png" ); m_imgCTop = QImage( strLeftPath + "_ctop.png" );
m_imgCCur = QImage( strLeftPath + "_ccur.png" );
m_imgCBut = QImage( strLeftPath + "_cbot.png" ); m_imgRTop = QImage( strLeftPath + "_rtop.png" );
m_imgRCur = QImage( strLeftPath + "_rcur.png" );
m_imgRBut = QImage( strLeftPath + "_rbot.png" );
} CPreviewWidge::~CPreviewWidge()
{
} QSize CPreviewWidge::sizeHint() const
{
int iHeight = m_imgLTop.height() + m_imgLCur.height() + m_imgLBut.height();
int iWidth = m_imgLTop.width() + m_imgCTop.width() + m_imgRTop.width(); return QSize( iWidth, iHeight );
} void CPreviewWidge::paintEvent ( QPaintEvent* e )
{
QWidget::paintEvent( e ); QPainter painter( this );
QRect r = rect(); painter.drawImage( r.topLeft().x(), r.topLeft().y(), m_imgLTop );
painter.drawImage( r.topRight().x() - m_imgRTop.width(), r.topRight().y(), m_imgRTop );
painter.drawImage( r.bottomLeft().x(), r.bottomLeft().y() - m_imgLBut.height(), m_imgLBut );
painter.drawImage( r.bottomRight().x() - m_imgRBut.width(), r.bottomRight().y() - m_imgRBut.height(), m_imgRBut ); QRect rectLCut( r.topLeft().x(), r.topLeft().y() + m_imgLTop.height(),
m_imgLCur.width(), ( r.bottomLeft().y() - r.topLeft().y() ) - m_imgLTop.height() - m_imgLBut.height() );
painter.drawImage( rectLCut, m_imgLCur ); QRect rectRCut( r.topRight().x() - m_imgRTop.width(), r.topRight().y() + m_imgRTop.height(),
m_imgRCur.width(), ( r.bottomLeft().y() - r.topLeft().y() ) - m_imgLTop.height() - m_imgLBut.height() );
painter.drawImage( rectRCut, m_imgRCur ); QRect rectCTop( r.topLeft().x() + m_imgLTop.width(), r.topLeft().y(),
( r.topRight().x() - r.topLeft().x() ) - m_imgLTop.width() - m_imgRTop.width(), m_imgCTop.height() );
painter.drawImage( rectCTop, m_imgCTop ); QRect rectCBot( r.bottomLeft().x() + m_imgLBut.width(), r.bottomLeft().y() - m_imgLBut.height(),
( r.topRight().x() - r.topLeft().x() ) - m_imgLTop.width() - m_imgRTop.width(), m_imgCBut.height() );
painter.drawImage( rectCBot, m_imgCBut ); QRect rectCCur( r.topLeft().x() + m_imgLTop.width(), r.topLeft().y() + m_imgLTop.height(),
( r.topRight().x() - r.topLeft().x() ) - m_imgLTop.width() - m_imgRTop.width(),
( r.bottomLeft().y() - r.topLeft().y() ) - m_imgLTop.height() - m_imgLBut.height() );
painter.drawImage( rectCCur, m_imgCCur );
}

Qt实现九宫图类控件的更多相关文章

  1. Qt 界面使用自己定义控件 &quot;提升为&quot;

    1.效果图 我做了一个很easy的样例,一个能够显示颜色的QLabel,边上有个button,点击,跳出颜色选取的Dialog,然后选择一个颜色.这个QLabel会变成什么颜色. 2.ColorLab ...

  2. Android RecyclerView滚动类控件修改、去掉滑动边界的阴影效果

    前言 滚动类控件,大家都用的很多,如 RecyclerView.NestedSrollView.... 下面以recyclerView为例讲解,其他滚动控件也同理. RecyclerView 滚动列表 ...

  3. PyQt(Python+Qt)学习随笔:布局控件layout的layoutSizeConstraint属性不起作用的问题解决办法

    在<PyQt(Python+Qt)学习随笔:布局控件layout的layoutSizeConstraint属性>中介绍layout的layoutSizeConstraint属性后,反复测试 ...

  4. Android一个炫酷的树状图组织架构图开源控件实现过程

    Android一个炫酷的树状图组织架构图开源控件 文章目录 [1 简介] [2 效果展示] [3 使用步骤] [4 实现基本布局流程] [5 实现自由放缩及拖动] [6 实现添加删除及节点动画] [7 ...

  5. kettle系列-[KettleUtil]kettle插件,类似kettle的自定义java类控件

    该kettle插件功能类似kettle现有的定义java类插件,自定java类插件主要是支持在kettle中直接编写java代码实现自定特殊功能,而本控件主要是将自定义代码转移到jar包,就是说自定义 ...

  6. 重新想象 Windows 8.1 Store Apps (77) - 控件增强: 文本类控件的增强, 部分控件增加了 Header 属性和 HeaderTemplate 属性, 部分控件增加了 PlaceholderText 属性

    [源码下载] 重新想象 Windows 8.1 Store Apps (77) - 控件增强: 文本类控件的增强, 部分控件增加了 Header 属性和 HeaderTemplate 属性, 部分控件 ...

  7. 基于Qt的第三方库和控件

    ====================== 基于Qt的第三方库和控件 ======================     libQxt --------   http://dev.libqxt.o ...

  8. C#控件系列--文本类控件

    C#控件系列--文本类控件         文本类控件主要包含Label.LinkLabel.Button.TextBox以及RichTextBox. Label 功能         Label用来 ...

  9. 八、pyqt5按钮类控件——QPushButton、QRadioButton、QCheckBox

    pyqt5中常用的按钮类控件有QPushButton.QRadioButton.QCheckBox.QToolButton等.这些按钮类的基类都是QAbstracButton类.所以这些类有部分方法是 ...

随机推荐

  1. 没有在xml中引入 相关的配置文件

    错误信息如下   严重: Servlet.service() for servlet AutoReplyServlet threw exception org.apache.ibatis.except ...

  2. spring +springmvc+mybatis组合总结

    springmvc+spring+mybatis整合:1. 拷贝所需jar2. 创建spring配置文件(beans.xml)3. 配置数据源 <bean id="dataSource ...

  3. Postgresql快速写入/读取大量数据(.net)

    环境及测试 使用.net驱动npgsql连接post数据库.配置:win10 x64, i5-4590, 16G DDR3, SSD 850EVO. postgresql 9.6.3,数据库与数据都安 ...

  4. com.mysql.jdbc.exceptions.jdbc4.MySQLSyntaxErrorException: Table 'portal.hibernate_sequence' doesn't exist, 谈谈主键自增的方式

    最近几天几天做项目用到了Spring Data JPA,确实是个好东西,省了很多力气.但是由于刚开始用,也遇到不少头疼的问题,如下,调用JpaRepository接口的save方法保存一个对象到数据库 ...

  5. DotNetCore跨平台~发布脚本PowerShell的设计

    回到目录 这几天对PS情有独忠,被它的强大功能所希引,它可以快速部署,快速发布,将一些连带的动作一次的完成,挺方便,类似于早期的bat文件,也像linux平台的bash脚本,但功能上,比前两者都要强很 ...

  6. 腾讯云centos7服务器环境搭建,tomcat+jdk+mysql+nginx

    软件:jdk 1.8.0_45 tomcat 8.5.8 mysql 5.6.36 nginx 1.10.x或以上 其中tomcat在centos6.8中没问题,centos7中会出现卡在启动那里 I ...

  7. Intellij Idea配置说明(从Eclipse转Idea)

      1.idea的字体大小设置 字体大小设置的方法: 进入Settings>>Editor>>Colors&Fonts>>Font,改变Size大小. 2. ...

  8. Missing number - 寻找缺失的那个数字

    需求:给出一个int型数组,包含不重复的数字0, 1, 2, ..., n:找出缺失的数字: 如果输入是[0, 1, 2] 返回 3 输入数组 nums = [0, 1, 2, 4] :应该返回 3 ...

  9. 号称精通Java的你,是否真的名副其实

    慎用精通 随着猎头行业的兴盛,一些应聘者往往可以从猎头那得到一些注意事项和过往经验.比如,在简历中切不可随意用上"精通"二字,尤其对于刚入职场的小伙伴. 因为,对于应聘者写上精通和 ...

  10. mysql内部级联删除

    1,创建user表 属性:id,name 2,创建userInfo表 属性:id,age 在userInfo表中创建外键id,如下图: 在user表中插入两个用户信息 (1,'1'),(2,'2') ...