문제

How to insert a background image in QListWidget and How to set the size of QListWidget?

QListWidget *list = new QListWidget();
list->addItem("Hello");
list->addItem("Hi");
도움이 되었습니까?

해결책

You have to set the background image through stylesheets using setStyleSheet.

list->setStyleSheet("background-image: url(image_url.png)");

If you want it to be in the center, just add:

list->setStyleSheet("background-image: url(image_url.png); background-position: center;");

If you want to set the size, you can do it through the stylesheet too as a fixed size:

list->setStyleSheet("background-image: url(image_url.png); max-width:100px;min-width:100px; max-height:100px; min-height:100px;");

Setting max and min of them is the same as doing this by code:

list->setSizePolicy(QSizePolicy::Fixed, QSizePolicy::Fixed);
list->setFixedSize(100,100);

Hope it helps.

다른 팁

list->setStyleSheet(QString("QListWidget { background-image: url(imagename.png) }"));

See documentation.

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top