第一步,新建一个项目删除所有与ui相关的代码。
设置窗口大小:
setFixedSize(150 + 1000 + 30,900);
添加布局、声明界面:
#include <QHBoxLayout>
QListWidget* pListWidget = nullptr;QScrollArea* pScrollArea = nullptr;pListWidget = new QListWidget(this);pScrollArea = new QScrollArea(this);QHBoxLayout* hlay = new QHBoxLayout(this);
将界面添加到布局中:
hlay->addWidget(pListWidget);hlay->addWidget(pScrollArea);
设置界面的大小:
pListWidget->setFixedWidth(150);
pScrollArea->setFixedWidth(1000+30);
为ListWidget添加选项:
QStringList pList;
pList<< u8" " << u8" " << u8" " << u8" ӹ " << u8" " << u8" "<< u8" " << u8" ";
pListWidget->addItems(pList);
为ListWidget设置样式:
string lw_qss = R"(QListWidget{/*border:1px solid gray; ߽ : ȡ ɫ*/background:rgb(26, 26, 26); /* ɫ*/color:rgb(200, 200, 200); /*ǰ ɫ ɫ*/font-size:15px;border-radius:1px;}QListWidget::item{height:40px;padding-left:10px; /* ı left ߵľ */}QListWidget::item:!active{background:rgb(26, 26, 26);margin:5px 20px 1px 20px; /* , item ListWidget ľ */}QListWidget::item:hover{background:rgb(56, 56, 56);padding-left:30px;}QListWidget::item:selected{border-radius:15px;background:lightblue;}/* ϴ ѡ ״̬ 뿪 ʾ*/QListWidget::item:selected:!active{background:rgb(51,51,51);color:#3F85FF;})";pListWidget->setStyleSheet(QString::fromStdString(lw_qss));