I create QListWidget with some items.
QHBoxLayout* h_layout = new QHBoxLayout;
h_layout->setMargin( 0 );
menu_list_widget_ = new QListWidget;
menu_list_widget_->setFlow(QListView::TopToBottom);
menu_list_widget_->setViewMode(QListView::IconMode);
menu_list_widget_->setMovement(QListView::Static);
menu_list_widget_->setFixedWidth( 100 );
QListWidgetItem* lwi;
menu_list_widget_->addItem( lwi = new QListWidgetItem(QIcon(":/icons/color_pencils.png"), "Цвета") );
lwi->setTextAlignment(Qt::AlignCenter);
menu_list_widget_->addItem( lwi = new QListWidgetItem(QIcon(":/icons/font.png"), "Шрифт") );
lwi->setTextAlignment(Qt::AlignCenter);
lwi->setHidden( true );
// etc
h_layout->addWidget(menu_list_widget_, 0, Qt::AlignHCenter)
But items don't have center align
Why?
I made some modification of your code, but the main is adding QListWidgetItem::setSizeHint()
for each element:
QListWidgetItem* lwi = new QListWidgetItem(QIcon(":Image/pinwheel.png"), "Цвета");
lwi->setSizeHint(QSize(256, 52));
listWidget->addItem( lwi );
lwi->setTextAlignment(Qt::AlignCenter);
lwi = new QListWidgetItem(QIcon(":Image/pinwheel.png"), "Управление и что-то еще");
lwi->setSizeHint(QSize(256, 52));
listWidget->addItem( lwi );
lwi->setTextAlignment(Qt::AlignCenter);
Now it looks aligned for me:
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With