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")); }
private void createActions() { addImagesAct = new QAction(tr("&Add Images..."), this); addImagesAct.setShortcut(tr("Ctrl+A")); addImagesAct.triggered.connect(this, "addImages()"); removeAllImagesAct = new QAction(tr("&Remove All Images"), this); removeAllImagesAct.setShortcut(tr("Ctrl+R")); removeAllImagesAct.triggered.connect(this, "removeAllImages()"); exitAct = new QAction(tr("&Quit"), this); exitAct.setShortcut(tr("Ctrl+Q")); exitAct.triggered.connect(this, "close()"); styleActionGroup = new QActionGroup(this); for (String styleName : QStyleFactory.keys()) { QAction action = new QAction(styleActionGroup); action.setText(styleName + " Style"); action.setData(styleName); action.setCheckable(true); action.triggered.connect(this, "changeStyle(boolean)"); } guessModeStateAct = new QAction(tr("&Guess Image Mode/State"), this); guessModeStateAct.setCheckable(true); guessModeStateAct.setChecked(true); aboutAct = new QAction(tr("&About"), this); aboutAct.triggered.connect(this, "about()"); aboutQtAct = new QAction(tr("About &Qt"), this); aboutQtAct.triggered.connect(QApplication.instance(), "aboutQt()"); }
private void checkCurrentStyle() { for (QAction action : styleActionGroup.actions()) { String styleName = action.data().toString(); QStyle candidate = QStyleFactory.create(styleName); if (candidate.objectName().equals(QApplication.style().objectName())) { action.trigger(); return; } } }
private void changeStyle(boolean checked) { if (!checked) return; QAction action = (QAction) QSignalEmitter.signalSender(); QStyle style = QStyleFactory.create((String) action.data()); if (style != null) { QApplication.setStyle(style); QApplication.setPalette(style.standardPalette()); } setTextOnRadioButtons(); changeSize(true); }
private void createActions() { openAct = new QAction(tr("&Open..."), this); openAct.setShortcut(tr("Ctrl+O")); openAct.triggered.connect(this, "open()"); saveAsActs = new LinkedList<QAction>(); for (QByteArray format : QImageWriter.supportedImageFormats()) { String text = new String(format.toByteArray()).toUpperCase() + "..."; QAction action = new QAction(text, this); action.setData(format); action.triggered.connect(this, "save()"); saveAsActs.add(action); } printAct = new QAction(tr("&Print..."), this); printAct.triggered.connect(scribbleArea, "print()"); exitAct = new QAction(tr("E&xit"), this); exitAct.setShortcut(tr("Ctrl+Q")); exitAct.triggered.connect(this, "close()"); penColorAct = new QAction(tr("&Pen Color..."), this); penColorAct.triggered.connect(this, "penColor()"); penWidthAct = new QAction(tr("Pen &Width..."), this); penWidthAct.triggered.connect(this, "penWidth()"); clearScreenAct = new QAction(tr("&Clear Screen"), this); clearScreenAct.setShortcut(tr("Ctrl+L")); clearScreenAct.triggered.connect(scribbleArea, "clearImage()"); aboutAct = new QAction(tr("&About"), this); aboutAct.triggered.connect(this, "about()"); aboutQtAct = new QAction(tr("About &Qt"), this); aboutQtAct.triggered.connect(QApplication.instance(), "aboutQt()"); }
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); } } }
private void save() { QAction action = (QAction) QSignalEmitter.signalSender(); QByteArray fileFormat = QVariant.toByteArray(action.data()); saveFile(new String(fileFormat.toByteArray())); }