QComboBox and QSpinBox in QTableWidget with appropriate alignment(QTableWidget 中的 QComboBox 和 QSpinBox 适当对齐)
问题描述
如何创建一个 QTable 小部件,它有 2 列,第一列有一个 QComboBox,第二列有一个 QSpinBox,这样组合框就获得了表格的所有空间,只有很小的地方留给QSpinBox(适用于 2-3 位数字).
How to create a QTable widget which has 2 columnes, and in first column there is a QComboBox and in the second column there is a QSpinBox so that the combo box gets all the space of table and only a very small place leaves for QSpinBox (for 2-3 digits).
推荐答案
首先使用 setCellWidget()
将 QComboBox
和 QSpinBox
设置为要在相应单元格中显示的小部件.
First, use setCellWidget()
to set the QComboBox
and QSpinBox
as the widgets to be displayed in the appropriate cell.
其次,使用horizontalHeader()
访问QHeaderView
为 QTableView
,然后设置 ResizeMode
相应.
Second, use horizontalHeader()
to access the QHeaderView
for the QTableView
, then set the ResizeMode
accordingly.
QTableWidget* table = new QTableWidget( this );
table->setColumnCount( 2 );
table->setRowCount( 1 );
table->setCellWidget ( 0, 0, new QComboBox( table ) );
table->setCellWidget ( 0, 1, new QSpinBox( table ) );
table->horizontalHeader()->setResizeMode( 0, QHeaderView::Stretch );
table->horizontalHeader()->setResizeMode( 1, QHeaderView::ResizeToContents );
这篇关于QTableWidget 中的 QComboBox 和 QSpinBox 适当对齐的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:QTableWidget 中的 QComboBox 和 QSpinBox 适当对齐


基础教程推荐
- 如何通过C程序打开命令提示符Cmd 2022-12-09
- 如何将 std::pair 的排序 std::list 转换为 std::map 2022-01-01
- 如何在 C++ 中初始化静态常量成员? 2022-01-01
- 如何检查GTK+3.0中的小部件类型? 2022-11-30
- 我有静态或动态 boost 库吗? 2021-01-01
- 静态库、静态链接动态库和动态链接动态库的 .lib 文件里面是什么? 2021-01-01
- 在 C++ 中计算滚动/移动平均值 2021-01-01
- C++结构和函数声明。为什么它不能编译? 2022-11-07
- 这个宏可以转换成函数吗? 2022-01-01
- 常量变量在标题中不起作用 2021-01-01