[Qt] CFlip 翻页功能实现
由于需要给table制作翻页功能,所以写了一个翻页的类。
看上去总体效果感觉还是不错的,哈哈。
#ifndef CFLIP_H
#define CFLIP_H
#include <QWidget>
#include <QPushButton>
#include <QLabel>
#include <QComboBox>
#include <QEvent>
class CFlip : public QWidget
{
Q_OBJECT
public:
CFlip(QWidget *parent = 0);
~CFlip();
int m_iSetPageInfo(int iAllPageNum, int iCurPageNo);
signals:
void sigPageChanged(int iPageNo);
public slots:
void slot_GotoPrePageBtn_clicked();
void slot_FirstPageBtn_clicked();
void slot_PrePageBtn_clicked();
void slot_CurPageBtn_clicked();
void slot_NextPageBtn_clicked();
void slot_LastPageBtn_clicked();
void slot_GotoNextPageBtn_clicked();
protected:
bool eventFilter(QObject *obj, QEvent *event);
private:
QPushButton *m_oGotoPrePageBtn;
QPushButton *m_oFirstPageBtn;
QPushButton *m_oPrePageBtn;
QPushButton *m_oCurPageBtn;
QPushButton *m_oNextPageBtn;
QPushButton *m_oLastPageBtn;
QPushButton *m_oGotoNextPageBtn;
int m_iAllPageNum;
int m_iCurPageNo;
};
#endif // CFLIP_H
#include "flip.h"
#include <QHBoxLayout>
CFlip::CFlip(QWidget *parent)
: QWidget(parent)
{
m_iAllPageNum = 1;
m_iCurPageNo = 1;
m_oGotoPrePageBtn = new QPushButton(this);
m_oFirstPageBtn = new QPushButton(this);
m_oPrePageBtn = new QPushButton(this);
m_oCurPageBtn = new QPushButton(this);
m_oNextPageBtn = new QPushButton(this);
m_oLastPageBtn = new QPushButton(this);
m_oGotoNextPageBtn = new QPushButton(this);
m_oGotoPrePageBtn->setMinimumSize(56, 23);
m_oFirstPageBtn->setMinimumSize(33, 23);
m_oPrePageBtn->setMinimumSize(23, 23);
m_oCurPageBtn->setMinimumSize(23, 23);
m_oNextPageBtn->setMinimumSize(23, 23);
m_oLastPageBtn->setMinimumSize(33, 23);
m_oGotoNextPageBtn->setMinimumSize(56, 23);
m_oGotoPrePageBtn->setMaximumSize(56, 23);
m_oFirstPageBtn->setMaximumSize(33, 23);
m_oPrePageBtn->setMaximumSize(23, 23);
m_oCurPageBtn->setMaximumSize(23, 23);
m_oNextPageBtn->setMaximumSize(23, 23);
m_oLastPageBtn->setMaximumSize(33, 23);
m_oGotoNextPageBtn->setMaximumSize(56, 23);
m_oGotoPrePageBtn->setText(tr("Prev"));
m_oFirstPageBtn->setText(tr("1..."));
m_oPrePageBtn->setText(tr("1"));
m_oCurPageBtn->setText(tr("1"));
m_oNextPageBtn->setText(tr("1"));
m_oLastPageBtn->setText(tr("...1"));
m_oGotoNextPageBtn->setText(tr("Next"));
QHBoxLayout *pHLayout = new QHBoxLayout();
pHLayout->setContentsMargins(1, 1, 1, 1);
pHLayout->addStretch();
pHLayout->addWidget(m_oGotoPrePageBtn);
pHLayout->addWidget(m_oFirstPageBtn);
pHLayout->addWidget(m_oPrePageBtn);
pHLayout->addWidget(m_oCurPageBtn);
pHLayout->addWidget(m_oNextPageBtn);
pHLayout->addWidget(m_oLastPageBtn);
pHLayout->addWidget(m_oGotoNextPageBtn);
this->setLayout(pHLayout);
this->setSizePolicy(QSizePolicy::Preferred, QSizePolicy::Preferred);
this->setMaximumSize(295, 23);
m_oFirstPageBtn->setHidden(true);
m_oPrePageBtn->setHidden(true);
m_oNextPageBtn->setHidden(true);
m_oLastPageBtn->setHidden(true);
this->setStyleSheet(
"QPushButton{border:1px solid #D7E2EE; border-radius:4px; background:#F5F5F5; color:#000; margin:1px;}"
"QPushButton:hover{border:1px solid #C5D3E3}"
);
m_oCurPageBtn->setStyleSheet("background: #006699;");
m_oGotoPrePageBtn->installEventFilter(this);
m_oFirstPageBtn->installEventFilter(this);
m_oPrePageBtn->installEventFilter(this);
m_oCurPageBtn->installEventFilter(this);
m_oNextPageBtn->installEventFilter(this);
m_oLastPageBtn->installEventFilter(this);
m_oGotoNextPageBtn->installEventFilter(this);
connect(m_oGotoPrePageBtn, SIGNAL(clicked()), this, SLOT(slot_GotoPrePageBtn_clicked()));
connect(m_oFirstPageBtn, SIGNAL(clicked()), this, SLOT(slot_FirstPageBtn_clicked()));
connect(m_oPrePageBtn, SIGNAL(clicked()), this, SLOT(slot_PrePageBtn_clicked()));
connect(m_oCurPageBtn, SIGNAL(clicked()), this, SLOT(slot_CurPageBtn_clicked()));
connect(m_oNextPageBtn, SIGNAL(clicked()), this, SLOT(slot_NextPageBtn_clicked()));
connect(m_oLastPageBtn, SIGNAL(clicked()), this, SLOT(slot_LastPageBtn_clicked()));
connect(m_oGotoNextPageBtn, SIGNAL(clicked()), this, SLOT(slot_GotoNextPageBtn_clicked()));
}
CFlip::~CFlip()
{
}
int
CFlip::m_iSetPageInfo(int iAllPageNum, int iCurPageNo)
{
if(iAllPageNum <= 0 || iCurPageNo <= 0 || iAllPageNum<iCurPageNo)
{
return -1;
}
m_iAllPageNum = iAllPageNum;
m_iCurPageNo = iCurPageNo;
m_oGotoPrePageBtn->setHidden(false);
m_oFirstPageBtn->setHidden(false);
m_oPrePageBtn->setHidden(false);
m_oCurPageBtn->setHidden(false);
m_oNextPageBtn->setHidden(false);
m_oLastPageBtn->setHidden(false);
m_oGotoNextPageBtn->setHidden(false);
m_oCurPageBtn->setText(QString::number(iCurPageNo, 10));
if(iCurPageNo==1)
{
m_oFirstPageBtn->setHidden(true);
m_oPrePageBtn->setHidden(true);
}
else if(iCurPageNo==2)
{
m_oFirstPageBtn->setHidden(true);
m_oPrePageBtn->setText(tr("1"));
}
else
{
m_oFirstPageBtn->setText(tr("1..."));
m_oPrePageBtn->setText(QString::number(iCurPageNo-1, 10));
}
if(iCurPageNo == iAllPageNum)
{
m_oNextPageBtn->setHidden(true);
m_oLastPageBtn->setHidden(true);
}
else if(iCurPageNo+1 == iAllPageNum)
{
m_oLastPageBtn->setHidden(true);
m_oNextPageBtn->setText(QString::number(iCurPageNo+1, 10));
}
else
{
m_oNextPageBtn->setText(QString::number(iCurPageNo+1, 10));
m_oLastPageBtn->setText(tr("...")+QString::number(m_iAllPageNum, 10));
}
return 0;
}
void
CFlip::slot_GotoPrePageBtn_clicked()
{
if(m_iSetPageInfo(m_iAllPageNum, m_iCurPageNo-1) == 0)
{
emit sigPageChanged(m_iCurPageNo);
}
}
void
CFlip::slot_FirstPageBtn_clicked()
{
if(m_iSetPageInfo(m_iAllPageNum, 1) == 0)
{
emit sigPageChanged(m_iCurPageNo);
}
}
void
CFlip::slot_PrePageBtn_clicked()
{
if(m_iSetPageInfo(m_iAllPageNum, m_iCurPageNo-1) == 0)
{
emit sigPageChanged(m_iCurPageNo);
}
}
void
CFlip::slot_CurPageBtn_clicked()
{
return;
}
void
CFlip::slot_NextPageBtn_clicked()
{
if(m_iSetPageInfo(m_iAllPageNum, m_iCurPageNo+1) == 0)
{
emit sigPageChanged(m_iCurPageNo);
}
}
void
CFlip::slot_LastPageBtn_clicked()
{
if(m_iSetPageInfo(m_iAllPageNum, m_iAllPageNum) == 0)
{
emit sigPageChanged(m_iCurPageNo);
}
}
void
CFlip::slot_GotoNextPageBtn_clicked()
{
if(m_iSetPageInfo(m_iAllPageNum, m_iCurPageNo+1) == 0)
{
emit sigPageChanged(m_iCurPageNo);
}
}
bool
CFlip::eventFilter(QObject *obj, QEvent *event)
{
QPushButton *pBtn = qobject_cast<QPushButton*>(obj);
if( (m_oGotoPrePageBtn == pBtn) ||
(m_oFirstPageBtn == pBtn) ||
(m_oPrePageBtn == pBtn) ||
(m_oCurPageBtn == pBtn) ||
(m_oNextPageBtn == pBtn) ||
(m_oLastPageBtn == pBtn) ||
(m_oGotoNextPageBtn == pBtn) )
{
if(event->type() == QEvent::Enter)
{
setCursor(Qt::PointingHandCursor);
}
}
return QObject::eventFilter(obj, event);
}
[Qt] CFlip 翻页功能实现的更多相关文章
- jsp实现上一页下一页翻页功能
前段时间一直忙于期末考试和找实习,好久没写博客了. 这段时间做了个小项目,包含了翻页和富文本编辑器Ueditor的两个知识点,Ueditor玩的还不是很深,打算玩深后再写篇博客. 要实现翻页功能,只需 ...
- Web测试——翻页功能测试用例
参考:https://wenku.baidu.com/view/e6462707de80d4d8d15a4f1e.html?rec_flag=default&mark_pay_doc=2&am ...
- Atitit 翻页功能的解决方案与版本历史 v4 r49
Atitit 翻页功能的解决方案与版本历史 v4 r49 1. 版本历史与分支版本,项目版本记录1 1.1. 主干版本历史1 1.2. 分支版本 项目版本记录.1 2. Easyui 的翻页组件2 ...
- Atitit.pagging 翻页功能解决方案专题 与 目录大纲 v3 r44.docx
Atitit.pagging 翻页功能解决方案专题 与 目录大纲 v3 r44.docx 1.1. 翻页的重要意义1 1.2. Dep废弃文档 paip.js翻页分页pageing组件.txt1 ...
- PyQt—QTableWidget实现翻页功能
主要使用QTableWidget中的三个函数实现: verticalScrollBar().setSliderPosition() 设置当前滑动条的位置 verticalScrollBar().max ...
- pyspider示例代码五:实现自动翻页功能
实现自动翻页功能 示例代码一 #!/usr/bin/env python # -*- encoding: utf- -*- # Created on -- :: # Project: v2ex fro ...
- jsp实现翻页功能
jsp实现翻页功能 要实现翻页功能,只需要设置一个pageIndex即可,然后每次加载页面时通过pageIndex去加载数据就行. 那么我们可以设置一个隐藏的input框,用于传递pageIndex给 ...
- jquery.Table实现的翻页功能比较完整漂亮,本想扩展个模版DIV
jquery.dataTable实现的翻页功能比较完整漂亮,本想提取其的翻页部分,再结合模版DIV,bootstrop实现聊天记息的展示. jquery.Table 与table结合的较紧,不能在很下 ...
- Webdriver控制翻页控件,并实现向前向后翻页功能,附上代码,仅供参考,其他类似日期控件的功能可以自己封装
新增输入与选择页面的html源码: <div style="margin-top:-60px;" class="modal-content" id=&qu ...
随机推荐
- 反编译 APKTool 逆向助手
最佳实践--Android逆向助手 1.点击"反编译apk,完成后res下的所有资源就都可以正常使用了,相当于apktool的功能------目前已失效,但是直接用rar解压是可以的!2.点 ...
- errno.h 错误码描述.
描述:一般说的Linux源码的目录,默认是基于 /usr/include/ 的. 使用 char *strerror(int errnum); 函数打印错误代码的描述.我简单对比了一下,发现描述大体一 ...
- mysql查询计划
mysql查询计划 1:客户端发起查询请求 2:服务器接收到请求后,先查询缓存 如果缓存命中,直接返回数据给客户端 否则,解析sql 3:sql解析完成后,进行预处理 4:有查询优化器生存查询计划 5 ...
- 武汉科技大学ACM :1006: 零起点学算法25——求两点之间的距离
Problem Description 输入平面坐标系中2点的坐标,输出它们之间的距离 Input 输入4个浮点数x1 y1 x2 y2,分别是点(x1,y1) (x2,y2)的坐标(多组数据) Ou ...
- 使用shiro安全框架上传文件时用HttpSession获取ServletContext为null问题解决方法。
<!--在shiroFilter 中加入一下配置--> <init-param> <param-name>targetFilterLifecycle</par ...
- jQuery get/post区别及contentType取值
1.GET访问 浏览器 认为 是等幂的 就是 一个相同的URL 只有一个结果[相同是指 整个URL字符串完全匹配]所以 第二次访问的时候 如果 URL字符串没变化浏览器是直接拿出了第一次访问的结果,表 ...
- centos 下mysql操作
MySQL名字的来历MySQL是一个小型关系型数据库管理系统,MySQL被广泛地应用在Internet上的中小型网站中.由于其体积小.速度 快.总体拥有成本低,尤其是开放源码这一特点,许多中小型网站为 ...
- Python3 如何优雅地使用正则表达式(详解二)
使用正则表达式 现在我们开始来写一些简单的正则表达式吧.Python 通过 re 模块为正则表达式引擎提供一个接口,同时允许你将正则表达式编译成模式对象,并用它们来进行匹配. 小甲鱼解释:re 模块是 ...
- HBase笔记--编程实战
HBase总结:http://blog.csdn.net/lifuxiangcaohui/article/details/39997205 (very good) Spark使用Java读取hbas ...
- Linux_cloudera-scm-agent: unrecognized service