Пример #1
1
  private void changeIcon() {
    QIcon icon = new QIcon();

    for (int row = 0; row < imagesTable.rowCount(); ++row) {
      QTableWidgetItem item0 = imagesTable.item(row, 0);
      QTableWidgetItem item1 = imagesTable.item(row, 1);
      QTableWidgetItem item2 = imagesTable.item(row, 2);

      if (item0.checkState() == Qt.CheckState.Checked) {
        QIcon.Mode mode;
        if (item1.text().equals(tr("Normal"))) {
          mode = QIcon.Mode.Normal;
        } else if (item1.text().equals(tr("Active"))) {
          mode = QIcon.Mode.Active;
        } else if (item1.text().equals(tr("Disabled"))) {
          mode = QIcon.Mode.Disabled;
        } else {
          mode = QIcon.Mode.Selected;
        }

        QIcon.State state;
        if (item2.text().equals(tr("On"))) {
          state = QIcon.State.On;
        } else {
          state = QIcon.State.Off;
        }

        String fileName = (String) item0.data(Qt.ItemDataRole.UserRole);
        QImage image = new QImage(fileName);
        if (!image.isNull()) icon.addPixmap(QPixmap.fromImage(image), mode, state);
      }
    }

    previewArea.setIcon(icon);
  }
Пример #2
0
  private void changeSize(boolean checked) {
    if (!checked) return;

    int extent;

    if (otherRadioButton.isChecked()) {
      extent = otherSpinBox.value();
    } else {
      QStyle.PixelMetric metric;

      if (smallRadioButton.isChecked()) {
        metric = QStyle.PixelMetric.PM_SmallIconSize;
      } else if (largeRadioButton.isChecked()) {
        metric = QStyle.PixelMetric.PM_LargeIconSize;
      } else if (toolBarRadioButton.isChecked()) {
        metric = QStyle.PixelMetric.PM_ToolBarIconSize;
      } else if (listViewRadioButton.isChecked()) {
        metric = QStyle.PixelMetric.PM_ListViewIconSize;
      } else if (iconViewRadioButton.isChecked()) {
        metric = QStyle.PixelMetric.PM_IconViewIconSize;
      } else {
        metric = QStyle.PixelMetric.PM_TabBarIconSize;
      }
      extent = QApplication.style().pixelMetric(metric);
    }
    previewArea.setSize(new QSize(extent, extent));
    otherSpinBox.setEnabled(otherRadioButton.isChecked());
  }