Example #1
0
  // ! [3]
  private void createControls(String title) {
    controlsGroup = new QGroupBox(title);

    minimumLabel = new QLabel(tr("Minimum value:"));
    maximumLabel = new QLabel(tr("Maximum value:"));
    valueLabel = new QLabel(tr("Current value:"));

    invertedAppearance = new QCheckBox(tr("Inverted appearance"));
    invertedKeyBindings = new QCheckBox(tr("Inverted key bindings"));

    // ! [3] //! [4]
    minimumSpinBox = new QSpinBox();
    // ! [4] //! [5]
    minimumSpinBox.setRange(-100, 100);
    minimumSpinBox.setSingleStep(1);

    maximumSpinBox = new QSpinBox();
    maximumSpinBox.setRange(-100, 100);
    maximumSpinBox.setSingleStep(1);

    valueSpinBox = new QSpinBox();
    valueSpinBox.setRange(-100, 100);
    valueSpinBox.setSingleStep(1);

    orientationCombo = new QComboBox();
    orientationCombo.addItem(tr("Horizontal slider-like widgets"));
    orientationCombo.addItem(tr("Vertical slider-like widgets"));

    // ! [5] //! [6]
    orientationCombo.activatedIndex.connect(stackedWidget, "setCurrentIndex(int)");
    // ! [6] //! [7]
    minimumSpinBox.valueChanged.connect(horizontalSliders, "setMinimum(int)");
    minimumSpinBox.valueChanged.connect(verticalSliders, "setMinimum(int)");
    maximumSpinBox.valueChanged.connect(horizontalSliders, "setMaximum(int)");
    maximumSpinBox.valueChanged.connect(verticalSliders, "setMaximum(int)");
    invertedAppearance.toggled.connect(horizontalSliders, "invertAppearance(boolean)");
    invertedAppearance.toggled.connect(verticalSliders, "invertAppearance(boolean)");
    invertedKeyBindings.toggled.connect(horizontalSliders, "invertedKeyBindings(boolean)");
    invertedKeyBindings.toggled.connect(verticalSliders, "invertedKeyBindings(boolean)");

    QGridLayout controlsLayout = new QGridLayout();
    controlsLayout.addWidget(minimumLabel, 0, 0);
    controlsLayout.addWidget(maximumLabel, 1, 0);
    controlsLayout.addWidget(valueLabel, 2, 0);
    controlsLayout.addWidget(minimumSpinBox, 0, 1);
    controlsLayout.addWidget(maximumSpinBox, 1, 1);
    controlsLayout.addWidget(valueSpinBox, 2, 1);
    controlsLayout.addWidget(invertedAppearance, 0, 2);
    controlsLayout.addWidget(invertedKeyBindings, 1, 2);
    controlsLayout.addWidget(orientationCombo, 3, 0, 1, 3);
    controlsGroup.setLayout(controlsLayout);
  }
 // ! [2]
 private void browse() {
   String directory = QFileDialog.getExistingDirectory(this, tr("Find Files"), QDir.currentPath());
   if (!directory.equals("")) {
     directoryComboBox.addItem(directory);
     directoryComboBox.setCurrentIndex(directoryComboBox.currentIndex() + 1);
   }
 }
  // ! [10]
  private QComboBox createComboBox(String text) {
    QComboBox comboBox = new QComboBox();
    comboBox.setEditable(true);
    comboBox.addItem(text);
    comboBox.setSizePolicy(QSizePolicy.Policy.Expanding, QSizePolicy.Policy.Preferred);

    return comboBox;
  }