QComboBox and QSpinBox in QTableWidget with appropriate alignment

前端 未结 1 490
孤街浪徒
孤街浪徒 2021-01-21 10:49

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 spac

1条回答
  •  爱一瞬间的悲伤
    2021-01-21 11:07

    First, use setCellWidget() to set the QComboBox and QSpinBox as the widgets to be displayed in the appropriate cell.

    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 );
    

    0 讨论(0)
提交回复
热议问题