QTableWidget中嵌套下拉显示框(QComboBox实现)

 在已经有 QTableWidget 的情况下:

 // 创建一个CustomComboBox对象
   wheer_speed_comboBox = new QComboBox();
    // 向CustomComboBox添加选项
   for(int i=0;iaddItem("轮 "+QString::number(i)+":NULL");//自定义下拉框文本
   }
    //自定义下拉框样式和点击按钮填充图片
   wheer_speed_comboBox->setStyleSheet("QComboBox { border:none;  background: #161D28; }"
               "QComboBox::drop-down { subcontrol-origin: padding;subcontrol-position: top right; width: 14px;"
               " border:none; padding-right:10px; } QComboBox::down-arrow { image: url(:image/MapManagement/icon/arrow.png); }");

    // 设置下拉列表的显示方式
    wheer_speed_comboBox->setView(new QListView());

    // 设置下拉列表的弹出策略
    wheer_speed_comboBox->setInsertPolicy(QComboBox::InsertPolicy::NoInsert);

    // 将QComboBox设置为不可编辑
    wheer_speed_comboBox->setEditable(true);
    wheer_speed_comboBox->lineEdit()->setReadOnly(true);
    //将下拉框插入到QTableWidget中指定行指定列
    ui->chassis_status_widget->setCellWidget(1,1,wheer_speed_comboBox);

你可能感兴趣的:(#,Qt,qt,开发语言)