예제 #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
  void changeHeight() {
    Integer newHeight =
        QInputDialog.getInteger(
            this,
            tr("Change table height"),
            tr("Input the number of rows required (1-20):"),
            tableWidget.rowCount(),
            1,
            20,
            1);

    if (newHeight != null) tableWidget.setRowCount(newHeight);
  }
예제 #3
0
  void setupTableItems() {
    // ! [1]
    tableWidget.setRowCount(10);
    tableWidget.setColumnCount(5);
    // ! [1]

    for (int row = 0; row < tableWidget.rowCount(); ++row) {
      for (int column = 0; column < tableWidget.columnCount(); ++column) {
        // ! [2]
        QTableWidgetItem newItem = new QTableWidgetItem("" + (row + 1) + ", " + (column + 1));
        tableWidget.setItem(row, column, newItem);
        // ! [2]
      }
    }
  }
예제 #4
0
  private void addImages() {
    List<String> fileNames =
        QFileDialog.getOpenFileNames(
            this,
            tr("Open Images"),
            "",
            new QFileDialog.Filter(tr("Images (*.png *.xpm *.jpg);;" + "All Files (*)")));
    if (!fileNames.isEmpty()) {
      for (String fileName : fileNames) {
        int row = imagesTable.rowCount();
        imagesTable.setRowCount(row + 1);

        String imageName = new QFileInfo(fileName).baseName();
        QTableWidgetItem item0 = new QTableWidgetItem(imageName);
        item0.setData(Qt.ItemDataRole.UserRole, fileName);
        Qt.ItemFlags flags = item0.flags();
        flags.clear(Qt.ItemFlag.ItemIsEditable);
        item0.setFlags(flags);

        QTableWidgetItem item1 = new QTableWidgetItem(tr("Normal"));
        QTableWidgetItem item2 = new QTableWidgetItem(tr("Off"));

        if (guessModeStateAct.isChecked()) {
          if (fileName.contains("_act")) {
            item1.setText(tr("Active"));
          } else if (fileName.contains("_dis")) {
            item1.setText(tr("Disabled"));
          } else if (fileName.contains("_sel")) {
            item1.setText(tr("Selected"));
          }

          if (fileName.contains("_on")) item2.setText(tr("On"));
        }

        imagesTable.setItem(row, 0, item0);
        imagesTable.setItem(row, 1, item1);
        imagesTable.setItem(row, 2, item2);
        imagesTable.openPersistentEditor(item1);
        imagesTable.openPersistentEditor(item2);

        item0.setCheckState(Qt.CheckState.Checked);
      }
    }
  }