def initUI(self): self.setWindowTitle("QTableWidget 例子") self.resize(430, 300); conLayout = QHBoxLayout() tableWidget = QTableWidget() tableWidget.setRowCount(4) tableWidget.setColumnCount(3) conLayout.addWidget(tableWidget) tableWidget.setHorizontalHeaderLabels(['姓名', '性别', '体重(kg)']) newItem = QTableWidgetItem("张三") tableWidget.setItem(0, 0, newItem) comBox = QComboBox() comBox.addItem("男") comBox.addItem("女") comBox.setStyleSheet("QComboBox{margin:3px};") tableWidget.setCellWidget(0, 1, comBox) searchBtn = QPushButton("修改") searchBtn.setDown(True) searchBtn.setStyleSheet("QPushButton{margin:3px};") tableWidget.setCellWidget(0, 2, searchBtn) self.setLayout(conLayout)
def initUI(self): box = QComboBox(self) box.resize(box.sizeHint()) box.setStyleSheet(""" QComboBox::drop-down {border-width: 0px;} QComboBox::down-arrow {image: url(noimg); border-width: 0px;} """) box.move(50, 50) #Using the palette doesn't work: pal = box.palette() pal.setColor(box.backgroundRole(), QColor()) box.setAutoFillBackground(True) box.setPalette(pal) self.setGeometry(300, 300, 250, 150) self.show()