社区
Qt
帖子详情
怎样定义QTableWidget中的CellWidget在table中的对齐方式?
高维橘子
2013-12-16 11:19:13
在QTableWidget中添加了一个CellWidget,是QLabel,其中Label上还有文字。
在label上设置了文字的对齐方式是Qt::AlignCenter,但是不知道怎么设置这个CellWidget在Table的格子里的对齐方式。
请问,怎么设置CellWidget在QTabelWidget中也是Qt::AlignCenter?
...全文
992
4
打赏
收藏
怎样定义QTableWidget中的CellWidget在table中的对齐方式?
在QTableWidget中添加了一个CellWidget,是QLabel,其中Label上还有文字。 在label上设置了文字的对齐方式是Qt::AlignCenter,但是不知道怎么设置这个CellWidget在Table的格子里的对齐方式。 请问,怎么设置CellWidget在QTabelWidget中也是Qt::AlignCenter?
复制链接
扫一扫
分享
转发到动态
举报
AI
作业
写回复
配置赞助广告
用AI写文章
4 条
回复
切换为时间正序
请发表友善的回复…
发表回复
打赏红包
wxiuqing856
2015-01-06
打赏
举报
回复
没有找到直接的接口,不过,可以自己模拟一下: 在cellwidget的外层添加一层透明窗体,在这层透明窗体上添加布局,将cellWidget放入布局中,对布局进行对齐设置。 示例代码: QWidget *translateWidget = new QWidget(m_ptablewnd); translateWidget->setObjectName("translateWidget"); translateWidget->setStyleSheet("background-color:rgba(0,0,0,0)"); QHBoxLayout *hbl = new QHBoxLayout(); hbl->setSpacing(0); hbl->setContentsMargins(0,0,0,0); hbl->setMargin(2); translateWidget->setLayout(hbl); QPushButton *button = new QPushButton (translateWidget); hbl->addWidget(button,1,Qt::AlignCenter); button->setToolTip("Hello"); button->setIcon(QIcon(a.png)); button->setFixedSize(64,64); hbl->addWidget(button); QTableWidget *tableWidget = QTableWidget(); tableWidget->setRowCount(1); tableWidget->setColumnCount(1); tableWidget->setCellWidget(0,0,translateWidget);
高维橘子
2013-12-16
打赏
举报
回复
引用 2 楼 lion_kangaxx 的回复:
似乎没有一蹴而就的办法,保持宽度一致应该可以吧?看看其他人有没有办法
谢谢!我也没有找到。
l4kangaxx
2013-12-16
打赏
举报
回复
似乎没有一蹴而就的办法,保持宽度一致应该可以吧?看看其他人有没有办法
Qt开发:
Q
Table
Widget
的介绍和使用
本文主要介绍Qt
中
Q
Table
Widget
的常用方法。
在
Q
Table
Widget
中
添加QCheckBox并居
中
QCheckBox * checkB = new QCheckBox(this); //创建checkbox checkB->setCheckState(Qt::Checked); //设置状态 Q
Widget
*w = new Q
Widget
(this); //创建一个
widget
QHBoxLayout *hLayout = new QHBoxLayout(); //创建布局 hLay...
Q
Table
Widget
的简单用法笔记。
QHeaderView对象代表表格的表头,可以对表头的样式做一系列设置。
Q
Table
Widget
Item* item
Q
Table
Widget
*
table
QHeaderView* head_view 1.禁止某个item编辑 item->setFlags(item->flags()&(~Qt::ItemIsEdi
table
)); 2.把某个单元格设置为
widget
,可
QT
Q
Table
Widget
用法总结
Q
Table
Widget
是QT程序
中
常用的显示数据表格的空间,很类似于VC、C#
中
的DataGrid。说到
Q
Table
Widget
,就必须讲一下它跟QTabelView的区别了。
Q
Table
Widget
是Q
Table
View的子类,主要的区别是Q
Table
View可以使用自
定义
的数据模型来显示内容(也就是先要通过setModel来绑定数据源),而
Q
Table
Widget
则只能使用标准的数据模型,并
Qt
Q
Table
Widget
表格控件的用法(非常详细)
Qt
Q
Table
Widget
表格控件的用法(非常详细)
Q
Table
Widget
是 Qt 提供的一种表格控件(如图 1 所示),类似于我们经常使用的 Excel 表格,可以将数据以表格的
方式
展示给用户。 整个
Q
Table
Widget
表格可以分为 3 个区域: 区域 ① 和 ② 都是表头,区域 ① 设置每一行的表头,区域 ② 设置每一列的表头。我们可以自
定义
两个区域内的表头,比如第一列是各个教程的名称,所以第一列的表头可以修改为“教程名称”; 区域 ③ 为数据区,表格
中
所有的数据都位于此区域,该区域内
Qt
16,819
社区成员
26,685
社区内容
发帖
与我相关
我的任务
Qt
Qt 是一个跨平台应用程序框架。通过使用 Qt,您可以一次性开发应用程序和用户界面,然后将其部署到多个桌面和嵌入式操作系统,而无需重复编写源代码。
复制链接
扫一扫
分享
社区描述
Qt 是一个跨平台应用程序框架。通过使用 Qt,您可以一次性开发应用程序和用户界面,然后将其部署到多个桌面和嵌入式操作系统,而无需重复编写源代码。
社区管理员
加入社区
获取链接或二维码
近7日
近30日
至今
加载中
查看更多榜单
社区公告
暂无公告
试试用AI创作助手写篇文章吧
+ 用AI写文章