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"));
  }
Beispiel #2
0
  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);
  }