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 适当对齐
基础教程推荐
- CString 到 char* 2021-01-01
- 为什么 typeid.name() 使用 GCC 返回奇怪的字符以及如 2022-09-16
- 如果我为无符号变量分配负值会发生什么? 2022-01-01
- 通过引用传递 C++ 迭代器有什么问题? 2022-01-01
- 初始化列表*参数*评估顺序 2021-01-01
- 为什么 RegOpenKeyEx() 在 Vista 64 位上返回错误代码 2021-01-01
- GDB 显示调用堆栈上函数地址的当前编译二进制文 2022-09-05
- 我应该对 C++ 中的成员变量和函数参数使用相同的名称吗? 2021-01-01
- 为什么派生模板类不能访问基模板类的标识符? 2021-01-01
- 非静态 const 成员,不能使用默认赋值运算符 2022-10-09
