Qt编程23:QListWidget简单应用
//构建QListWidget对象
listWin = new QListWidget(this);
//设置item对齐方式
listWin->setFlow(QListWidget::LeftToRight);
//设置调色板
QPalette pal;
//设置交替颜色
pal.setColor(QPalette::AlternateBase,QColor(Qt::gray));
//设置文字颜色
pal.setColor(QPalette::Text,QColor(Qt::blue));
//设置背景色
pal.setColor(QPalette::Base,QColor(148,220,145));
//设置颜色交替
listWin->setAlternatingRowColors(true);
//在listWin中加入item
listWin->setPalette(pal);
listWin->addItem(new QListWidgetItem(QIcon(":/new/listWidget/dialog-close.png"),"关闭按钮\nsdfs\nsssss"));
listWin->addItem(new QListWidgetItem(QIcon(":/new/listWidget/dialog-cancel.png"),"取消按钮"));
listWin->addItem(new QListWidgetItem(QIcon(":/new/listWidget/dialog-close.png"),"关闭按钮\nsdfs"));
listWin->addItem(new QListWidgetItem(QIcon(":/new/listWidget/settings.png"),"设置按钮"));
listWin->addItem(new QListWidgetItem(QIcon(":/new/listWidget/task-ongoing.png"),"任务按钮"));
listWin->addItem(new QListWidgetItem(QIcon(":/new/listWidget/view-refresh.png"),"刷新按钮"));
//设置显示模式为图标模式
listWin->setViewMode(QListWidget::IconMode);
//设置可以换行显示
listWin->setLayoutMode(QListWidget::Batched);
//不接受拖放
listWin->setAcceptDrops(false);
//开启排序功能
listWin->setSortingEnabled(true);
//设置当前活动行为3
listWin->setCurrentRow(2);
listWin->setEditTriggers(QListWidget::DoubleClicked);
//将listWin加入布局
ui->verticalLayout->addWidget(listWin);