Ignore:
Timestamp:
Aug 11, 2025, 5:43:56 PM (2 months ago)
Author:
Frederik Heber <frederik.heber@…>
Branches:
Candidate_v1.7.0, stable
Children:
641550
Parents:
6294b6
git-author:
Frederik Heber <frederik.heber@…> (05/03/24 15:25:52)
git-committer:
Frederik Heber <frederik.heber@…> (08/11/25 17:43:56)
Message:

Adds qt_size and qt_position arguments to control Qt window size.

  • override is only temporary and is not stored in QSettings.
  • this allows using these parameters in scripts to take screenshots in a reliable manner but retain the actual window size for other usages.
File:
1 edited

Legend:

Unmodified
Added
Removed
  • src/UIElements/Qt4/QtMainWindow.cpp

    r6294b6 rc41ce0  
    158158  QSettings settings;
    159159  settings.beginGroup("MainWindow");
    160   resize(settings.value("size", QSize(400, 400)).toSize());
    161   move(settings.value("position", QPoint(200, 200)).toPoint());
     160  settingsSize = settings.value("size", QSize(400, 400)).toSize();
     161  settingsPosition = settings.value("position", QPoint(200, 200)).toPoint();
     162
     163  const QStringList args = QCoreApplication::arguments();
     164  LOG(2, "DEBUG: QApp's seen arguments are " << args.join(",").toStdString());
     165
     166  const int indexSize = args.indexOf(QString("--qt_size"));
     167  const int indexPosition = args.indexOf(QString("--qt_position"));
     168
     169  if ((indexSize == -1) || (indexPosition == -1)) {
     170    resize(settingsSize);
     171    move(settingsPosition);
     172  } else {
     173    // Take size and position from command-line values instead
     174    // NOTE: Qt 4.8's toInt() caps the second argument when it's below 1000 (yes, really!). Hence, we're using stoi()
     175    const QSize cmdlineSize = QSize(stoi(args[indexSize + 1].split(",")[0].toStdString()), stoi(args[indexSize + 1].split(",")[1].toStdString()));
     176    const QPoint cmdlinePosition = QPoint(stoi(args[indexPosition + 1].split(",")[0].toStdString()), stoi(args[indexPosition + 1].split(",")[1].toStdString()));
     177    LOG(2, "DEBUG: Using size and position from the command line: (" << cmdlineSize.width() << "," << cmdlineSize.height()
     178        << "), (" << cmdlinePosition.x() << "," << cmdlinePosition.y() << ")");
     179    resize(cmdlineSize);
     180    move(cmdlinePosition);
     181  }
    162182  if (settings.value("maximized", false).toBool())
    163183    showMaximized();
    164184  settings.endGroup();
     185  LOG(1, "INFO: Size and position is (" << size().width() << "," << size().height() << "), (" << pos().x() << "," << pos().y() << ")");
    165186
    166187  connect(glWorldView,SIGNAL(hoverChanged(const atomId_t)), infoBox,SLOT(atomHover(const atomId_t)));
     
    174195QtMainWindow::~QtMainWindow()
    175196{
     197  const QStringList args = QCoreApplication::arguments();
     198  const bool containsSize = args.contains(QString("--qt_size"));
     199  const bool containsPosition = args.contains(QString("--qt_position"));
     200
    176201  QSettings settings;
    177202  settings.beginGroup("MainWindow");
    178   settings.setValue("size", size());
    179   settings.setValue("position", pos());
     203  if (!containsSize || !containsPosition) {
     204    settings.setValue("size", size());
     205    settings.setValue("position", pos());
     206  } else {
     207    settings.setValue("size", settingsSize);
     208    settings.setValue("position", settingsPosition);
     209  }
    180210  settings.setValue("maximized", isMaximized());
    181211  settings.endGroup();
Note: See TracChangeset for help on using the changeset viewer.