[kde] RomDataViewPrivate::createOptionsButton(): Use HelpRole for the 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.
This commit is contained in:
David Korth 2024-03-03 01:29:02 -05:00
parent d0a91c881e
commit 3fee9e5e09

View File

@ -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)));