I put a button in the list widget, but the position of the button is strange.
Unsolved
General and Desktop
-
I put a button in the list widget, but the position of the button is strange.
void wCellTypeInfo::InitListItems() { for (int i = (int)CATEGORY::Single; i < (int)CATEGORY::Max; i++) { QListWidgetItem* item = new QListWidgetItem(this->ui.listWidget); QPushButton* pBtn = new QPushButton(); { pBtn->setFocusPolicy(Qt::NoFocus); pBtn->setMinimumSize(40,80); pBtn->setText(QString("%1").arg(i)); pBtn->setStyleSheet("Text-align: center"); } this->ui.listWidget->setItemWidget(item, pBtn); this->ui.listWidget->addItem(item); } }
-
@IknowQT said in I put a button in the list widget, but the position of the button is strange.:
but the position of the button is strange
What does "strange" mean exactly?
-
Hi,
Why are you using a QListWidget if you want to show a column of QPushButton ? A QVBoxLayout is better suited for that.
Beside that, setItemWidget is not meant for what you are trying to do.