#include <QApplication>

#include <QTableWidget>
#include <QPainter>
#include <QStyledItemDelegate>
#include <QHeaderView>
class QLineDelegate : public QStyledItemDelegate
{
public:
 QLineDelegate(QTableView* tableView);
protected:
 void paint(QPainter* painter, const QStyleOptionViewItem& option, const QModelIndex& index) const;
private:
 QPen pen;
 QTableView* view;
};
QLineDelegate::QLineDelegate(QTableView* tableView)
{
 int gridHint = tableView->style()->styleHint(QStyle::SH_Table_GridLineColor, new QStyleOptionViewItemV4());
 QColor gridColor = static_cast<QRgb>(gridHint);
 pen = QPen(gridColor, 0, tableView->gridStyle());
 view = tableView;
}
void QLineDelegate::paint(QPainter* painter, const QStyleOptionViewItem& option,const QModelIndex& index)const
{
 QStyledItemDelegate::paint(painter, option, index);
 QPen oldPen = painter->pen();
 painter->setPen(pen);
 //painter->drawLine(option.rect.topRight(), option.rect.bottomRight());
 painter->drawLine(option.rect.bottomLeft(), option.rect.bottomRight());
 painter->setPen(oldPen);
}
class QLineTableWidget:public QTableWidget
{
public:
 QLineTableWidget();
};
QLineTableWidget::QLineTableWidget()
{
 setStyleSheet("QTableView::Item{selection-">);
 setStyleSheet("QTableView::Item{">);
 verticalHeader()->setVisible(false);
 horizontalHeader()->setVisible(true);
 setSelectionBehavior(QAbstractItemView::SelectRows);
 setSelectionMode(QAbstractItemView::SingleSelection);
 setEditTriggers(QTableView::NoEditTriggers);
 setColumnCount(3);
 setRowCount(4);
 setShowGrid(false);
 setItemDelegate(new QLineDelegate(this));
 setCurrentCell(-1,-1);
}
int main(int argc,char **argv)
{
 QApplication a(argc,argv);
 QLineTableWidget widget;
 widget.show();
 return a.exec();
}

QTableview 只显示横向线的更多相关文章

  1. Table边框使用总结 ,只显示你要显示的边框

    表格的常用属性 基本属性有:width(宽度).height(高度).border(边框值).cellspacing(表格的内宽,即表格与tr之间的间隔). cellpadding(表格内元素的间隔, ...

  2. PADS Layout VX.2.3 灌铜之后只显示灌铜外框,没有显示整块铜皮

    操作系统:Windows 10 x64 工具1:PADS Layout VX.2.3 使用Copper Pour功能,画了一个灌铜区,并分配了网络. Tools > Pour Manager,打 ...

  3. win7系统的右键菜单只显示一个白色框不显示菜单项 解决办法

    如上图所示,桌面或其他大部分地方点击右键菜单,都只显示一个白色框,鼠标移上去才有菜单项看,并且效果很丑 解决办法: 计算机-右键-属性-高级-性能-设置-视觉效果-淡入淡出或滑动菜单到视图,将其前面的 ...

  4. AD域-让共享目录只显示用户有权限访问的文件夹

    问题: 在AD域中,我们一般都会用到共享,如果有很多部门,我们可能还会按部门.职位配置权限.比如CSD,IT,PA等,但文件夹一多,用户看着就头大,而且用户没权限访问的文件夹误点击进去还会提示无权限访 ...

  5. 关于datepicker只显示年、月、日的设置

    关键时侯,还得看官方文档.花了半个多小时,找了网上一大堆答复,然后一一验证,90%没有能解决问题. 先给出官方文档的URL: http://bootstrap-datepicker.readthedo ...

  6. 自定义RatingBar的一个问题(只显示显示一个星星)

    问题一: 在自定义RatingBar时在设置了numStars属性后只显示一张图(一个星星) 解答: 注意准备的替换图片千万不要使用.9PNG格式的图片,要不之后显示一张图(一个星星)! 问题二: 设 ...

  7. img只显示图片一部分 或 css设置背景图片只显示图片指定区域

    17:14 2016/3/22img只显示图片一部分 或 css设置背景图片只显示图片指定区域 background-position: 100% 56%; 设置背景图片显示图片的哪个坐标区域,图片左 ...

  8. WPF DatePicker只显示年和月 修改:可以只显示年

    最近的项目,查询时只需要年和月,不需要日,因此需要对原有的DatePicker进行修改,查询了网上的内容,最终从一篇帖子里看到了添加附加属性的方法,地址是http://stackoverflow.co ...

  9. ScrollView中嵌套GridView,ListView只显示一行的解决办法

    转载:http://blog.csdn.net/luohai859/article/details/39347583 关于为什么只显示一行,个人理解是:如果单独使用GridView和ListView, ...

随机推荐

  1. jquery实现淘宝动态图展示商品

    <!DOCTYPE html> <html> <head lang="en"> <meta charset="UTF-8&quo ...

  2. FPGA基础学习(3) -- 跨时钟域处理方法

    文章主要是基于学习后的总结. 1. 时钟域 假如设计中所有的触发器都使用一个全局网络,比如FPGA的主时钟输入,那么我们说这个设计只有一个时钟域.假如设计有两个输入时钟,如图1所示,一个时钟给接口1使 ...

  3. 115th LeetCode Weekly Contest Prison Cells After N Days

    There are 8 prison cells in a row, and each cell is either occupied or vacant. Each day, whether the ...

  4. [转] JAVA从本机获取IP地址

    [From] https://www.cnblogs.com/xiaoBlog2016/p/7076230.html 论述: 此篇博客是在工作的时候,需要获得当前网络下面正确的ip地址,在网上查阅很多 ...

  5. Djang视图层

    视图 1.什么是视图 视图就是Django项目下的view.py,它的内部是一系列的函数或者是类,用来专门处理客户端访问请求并且返回相应的数据,相当于一个中央处理系统. 2.具体视图实例 3.CBV和 ...

  6. 修改TrustedInstaller权限文件

    我们在删除文件的时候有可能出现无法删除,并且需要TrustedInstaller提供的权限,所以我们主要修改该文件的拥有者(修改为本机用户)即可.下文举例哦,方法如下: 总结起来:修改文件的所有着为本 ...

  7. 2.5 References & Borrowing

    Here is how you would define and use a calculate_length function that has a reference to an object a ...

  8. Java - 打印质数(使用控制嵌套循环跳转)

    使用控制嵌套循环跳转,打印输出10 ~ 150之间的质数 代码: public class Testcotinue { public static void main(String[] args) { ...

  9. c#实现常用排序算法

    让我们先看一看常用排序算法的效率对比 接着请看代码和注释~ using System; using System.Collections.Generic; using System.Linq; usi ...

  10. (转)CentOS/Linux 解决 SSH 连接慢

    CentOS/Linux 解决 SSH 连接慢 原文:http://blog.csdn.net/doiido/article/details/43793391 现在连接linux服务器一般都是使用SS ...