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); }
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); }
void changeWidth() { Integer newWidth = QInputDialog.getInteger( this, tr("Change table width"), tr("Input the number of columns required (1-20):"), tableWidget.columnCount(), 1, 20, 1); if (newWidth != null) tableWidget.setColumnCount(newWidth); }
private void createImagesGroupBox() { imagesGroupBox = new QGroupBox(tr("Images")); imagesTable = new QTableWidget(); imagesTable.setSelectionMode(QAbstractItemView.SelectionMode.NoSelection); imagesTable.setItemDelegate(new ImageDelegate(this)); List<String> labels = new LinkedList<String>(); labels.add(tr("Image")); labels.add(tr("Mode")); labels.add(tr("State")); imagesTable.horizontalHeader().setDefaultSectionSize(90); imagesTable.setColumnCount(3); imagesTable.setHorizontalHeaderLabels(labels); imagesTable.horizontalHeader().setResizeMode(0, QHeaderView.ResizeMode.Stretch); imagesTable.horizontalHeader().setResizeMode(1, QHeaderView.ResizeMode.Fixed); imagesTable.horizontalHeader().setResizeMode(2, QHeaderView.ResizeMode.Fixed); imagesTable.verticalHeader().hide(); imagesTable.itemChanged.connect(this, "changeIcon()"); QVBoxLayout layout = new QVBoxLayout(); layout.addWidget(imagesTable); imagesGroupBox.setLayout(layout); }
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] } } }
public mainwindow() { QMenu fileMenu = new QMenu(tr("File")); QAction quitAction = fileMenu.addAction(tr("Exit")); quitAction.setShortcut(tr("Ctrl+Q")); QMenu tableMenu = new QMenu(tr("Table")); QAction tableWidthAction = tableMenu.addAction(tr("Change Table Width")); QAction tableHeightAction = tableMenu.addAction(tr("Change Table Height")); menuBar().addMenu(fileMenu); menuBar().addMenu(tableMenu); // ! [0] tableWidget = new QTableWidget(this); // ! [0] tableWidget.setSelectionMode(QAbstractItemView.SelectionMode.ExtendedSelection); quitAction.triggered.connect(this, "close()"); tableWidthAction.triggered.connect(this, "changeWidth()"); tableHeightAction.triggered.connect(this, "changeHeight()"); setupTableItems(); setCentralWidget(tableWidget); setWindowTitle(tr("Table Widget Resizing")); }
void retranslateUi(QWidget AnalisisForm) { AnalisisForm.setWindowTitle( com.trolltech.qt.core.QCoreApplication.translate("AnalisisForm", "Form", null)); tableWidget.clear(); tableWidget.setColumnCount(0); tableWidget.setRowCount(0); groupBox.setTitle( com.trolltech.qt.core.QCoreApplication.translate("AnalisisForm", "Acciones", null)); pasosButton.setText( com.trolltech.qt.core.QCoreApplication.translate("AnalisisForm", "Pasos", null)); completoButton.setText( com.trolltech.qt.core.QCoreApplication.translate("AnalisisForm", "Completo", null)); groupBox_2.setTitle(""); cerrarButton.setText( com.trolltech.qt.core.QCoreApplication.translate("AnalisisForm", "Cerrar", null)); } // retranslateUi
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); } } }
public void setupUi(QWidget AnalisisForm) { AnalisisForm.setObjectName("AnalisisForm"); AnalisisForm.resize(new QSize(568, 351).expandedTo(AnalisisForm.minimumSizeHint())); gridLayout_3 = new QGridLayout(AnalisisForm); gridLayout_3.setObjectName("gridLayout_3"); horizontalLayout = new QHBoxLayout(); horizontalLayout.setObjectName("horizontalLayout"); tableWidget = new QTableWidget(AnalisisForm); tableWidget.setObjectName("tableWidget"); horizontalLayout.addWidget(tableWidget); verticalLayout_2 = new QVBoxLayout(); verticalLayout_2.setObjectName("verticalLayout_2"); groupBox = new QGroupBox(AnalisisForm); groupBox.setObjectName("groupBox"); groupBox.setMinimumSize(new QSize(0, 0)); gridLayout = new QGridLayout(groupBox); gridLayout.setObjectName("gridLayout"); verticalLayout = new QVBoxLayout(); verticalLayout.setObjectName("verticalLayout"); pasosButton = new QPushButton(groupBox); pasosButton.setObjectName("pasosButton"); verticalLayout.addWidget(pasosButton); completoButton = new QPushButton(groupBox); completoButton.setObjectName("completoButton"); verticalLayout.addWidget(completoButton); gridLayout.addLayout(verticalLayout, 0, 0, 1, 1); verticalLayout_2.addWidget(groupBox); groupBox_2 = new QGroupBox(AnalisisForm); groupBox_2.setObjectName("groupBox_2"); groupBox_2.setMaximumSize(new QSize(16777215, 80)); gridLayout_2 = new QGridLayout(groupBox_2); gridLayout_2.setObjectName("gridLayout_2"); cerrarButton = new QPushButton(groupBox_2); cerrarButton.setObjectName("cerrarButton"); gridLayout_2.addWidget(cerrarButton, 0, 0, 1, 1); verticalLayout_2.addWidget(groupBox_2); horizontalLayout.addLayout(verticalLayout_2); gridLayout_3.addLayout(horizontalLayout, 0, 0, 1, 1); retranslateUi(AnalisisForm); cerrarButton.clicked.connect(AnalisisForm, "close()"); AnalisisForm.connectSlotsByName(); } // setupUi
private void createContextMenu() { imagesTable.setContextMenuPolicy(Qt.ContextMenuPolicy.ActionsContextMenu); imagesTable.addAction(addImagesAct); imagesTable.addAction(removeAllImagesAct); }
private void removeAllImages() { imagesTable.setRowCount(0); changeIcon(); }