【发布时间】:2019-12-17 12:56:44
【问题描述】:
我有一个应用程序可以动态创建 QLabels 以显示文件夹中存在的不同数量的图像。
以下是我用来创建这些标签的代码:
// dynamically displaying images
int n = 0;
int row = 0;
while (row >= 0) {
for (int col = 0; col < 4; col++) {
if (n < noOfImagesInSkippedFolder) {
// image exists
intToString = to_string(n);
cout << skippedImageName << endl;
QLabel *labelName = new QLabel();
labelName->setFixedHeight(100);
labelName->setFixedWidth(100);
labelName->setStyleSheet("background-color: rgb(255, 255, 255); border: 1px solid rgb(60, 60, 60);");
imageToDisplay = imread("bin/skippedAkshars/" + intToString + ".jpg", CV_LOAD_IMAGE_GRAYSCALE);
QImage srcImage = QImage(imageToDisplay.data, imageToDisplay.cols, imageToDisplay.rows, imageToDisplay.step, QImage::Format_Grayscale8);
int w = labelName->width();
int h = labelName->height();
labelName->setPixmap(QPixmap::fromImage(srcImage).scaled(w,h, Qt::KeepAspectRatio));
ui->gridLayout->addWidget(labelName, row, col);
n = n + 1;
}
else { // images does not exist
goto done;
}
}
row++;
}
done:
cout << "done!" << endl;
我想使用鼠标单击选择多个这些图像并删除选定的图像。 有人可以帮我吗?
【问题讨论】:
-
您是想通过单击来累积选择,还是想要橡皮筋选择之类的东西?
-
顺便说一句。如果你会使用例如
QTableWidget作为图像的容器或类似的东西,然后你会得到“免费”的选择。 -
我想通过单击来累积选择