Skip to content

Commit

Permalink
[kde] RomDataViewPrivate::createOptionsButton(): Use HelpRole for the…
Browse files Browse the repository at this point in the history
… Options button.

On Qt4 and Qt5, we could add a stretch layout item to the
QDialogButtonBox's layout directly. On Qt6, this doesn't seem
to work properly, since a bunch of internals were changed.

Using HelpRole instead of ActionRole seems to provide the same effect
on Qt6, and I tested that it works on Qt5 as well, so it will probably
work on Qt4. (TODO: Test it.)

Note that since the button has HelpRole, it might cause the
QDialogButotnBox to emit the helpRequested() signal. Nothing appears
to connect to this signal by default, so it's not an issue.
  • Loading branch information
GerbilSoft committed Mar 3, 2024
1 parent d0a91c8 commit 3fee9e5
Showing 1 changed file with 5 additions and 20 deletions.
25 changes: 5 additions & 20 deletions src/kde/RomDataView.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -96,28 +96,13 @@ void RomDataViewPrivate::createOptionsButton(void)
// Create the "Options" button.
btnOptions = new OptionsMenuButton();
btnOptions->setObjectName(QLatin1String("btnOptions"));
btnBox->addButton(btnOptions, QDialogButtonBox::ActionRole);
// NOTE: Using HelpRole to force the button to the left side of the dialog.
// The previous method added a stretch layout item to the QDialogButtonBox's
// layout directly, but that doesn't appear to work on Qt6.
// TODO: Verify that this works correctly on Qt4. (works on Qt5)
btnBox->addButton(btnOptions, QDialogButtonBox::HelpRole);
btnOptions->hide();

// Add a spacer to the QDialogButtonBox.
// This will ensure that the "Options" button is left-aligned.
QBoxLayout *const boxLayout = findDirectChild<QBoxLayout*>(btnBox);
if (boxLayout) {
// Find the index of the "Options" button.
const int count = boxLayout->count();
int idx = -1;
for (int i = 0; i < count; i++) {
if (boxLayout->itemAt(i)->widget() == btnOptions) {
idx = i;
break;
}
}

if (idx >= 0) {
boxLayout->insertStretch(idx+1, 1);
}
}

// Connect the OptionsMenuButton's triggered(int) signal.
QObject::connect(btnOptions, SIGNAL(triggered(int)),
q, SLOT(btnOptions_triggered(int)));
Expand Down

0 comments on commit 3fee9e5

Please sign in to comment.