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 适当对齐


- 静态初始化顺序失败 2022-01-01
- 与 int by int 相比,为什么执行 float by float 矩阵乘法更快? 2021-01-01
- C++ 协变模板 2021-01-01
- 使用/clr 时出现 LNK2022 错误 2022-01-01
- STL 中有 dereference_iterator 吗? 2022-01-01
- Stroustrup 的 Simple_window.h 2022-01-01
- 近似搜索的工作原理 2021-01-01
- 从python回调到c++的选项 2022-11-16
- 如何对自定义类的向量使用std::find()? 2022-11-07
- 一起使用 MPI 和 OpenCV 时出现分段错误 2022-01-01