Qt 5.7 QFileDialog action doesn't work - macos

I got filedialog called inside my main window with this code:
QAction *actionWithShortcut = new QAction();
actionWithShortcut->setShortcut(Qt::CTRL + Qt::Key_9);
actionWithShortcut->setShortcutContext(Qt::ShortcutContext::WidgetWithChildrenShortcut);
// added this comment to check does it work at list outside filedialog
// addAction(actionWithShortcut);
QFileDialog *fd = new QFileDialog(this);
fd->addAction(actionWithShortcut);
connect(actionWithShortcut, &QAction::triggered, fd, &QFileDialog::reject);
fd->show();
But looks like I can't add any actions to QFileDialog or they are somehow omitted. Any suggestions?
Already tried window flags, options and etc. Can't find any solutions.

By default, a QFileDialog is a thin wrapper around the native dialog. Qt didn't go to the lengths needed to wrap actions around the native dialog. So this is a case of a missing implementation. You could patch Qt to make it work on a platform of your choice, and contribute the change back, of course.
The action would presumably work if you were to switch to a non-native file dialog.

Related

Crash when calling getOpenFileName from QItemDelegate's custom editor

Prerequisites:
I have a custom QItemDelegate which creates custom editor for treeview items.
The editor consists of a QLineEdit and QToolButton. The button is used to open the file dialog for selecting the file and placing it's path into line edit.
I use a call to QFileDialog::getOpenFileName to open the file dialog. The dialog is native Windows file dialog (this is important).
When the editor is created the first time, everything works ok no matter how often I press that button. But after the editor is closed and reopened again the first press on the button results in a crash. The reason of the crash is that my custom editor eventually gets deleted.
Here is some code:
void CCustomEditor::on_RunSetupBtn_clicked()
{
auto qFilename = QFileDialog::getOpenFileName(this,
"Select application to run",
QString(),
"Executable files (*.exe)");
if (qFilename.isEmpty())
return;
SetCommandLine(QDir::toNativeSeparators(qFilename), m_qParameters);
}
I have made some digging and found out that calling WinAPI function GetOpenFileName results in the very same way: my editor gets deleted (although crash doesn't happen). It seems that Qt calls it also internally.
I have tracked down the reason of why my editor gets deleted and found out that when getOpenFileName is called, active window changes and focus changes with it.
In the first case the focus is moved from TreeView item, but in the second case it is moved from the editor itself!
This results in the deletion of editor because of 'focus out' event.
It is important to say that this situation doesn't happen if 'DontUseNativeDialog' flag is set when file dialog is created. Therefore this should be a bug in Qt's window management between native windows and Qt widgets.
As a workaround of this bug I suggest the following solution: before making a call to getOpenFileName set the focus to the button itself.
m_pUI->RunSetupBtn->setFocus();
auto qFilename = QFileDialog::getOpenFileName(this,
"Select application to run",
QString(),
"Executable files (*.exe)");
The other workaround is to use 'DontUseNativeDialog' flag, but the resulting file dialog doesn't look native, in fact it is quite ugly.
If someone has a better solution, feel free to share.
I have a similar problem with getOpenFileName and getSaveFileName. My solution is, after getOpenFileName, getSaveFileName or at the end of the function set the windows as active with activateWindow().

Create Transparent Windows in Haxe (Neko or Windows targets)

Im trying to make a simple OSX-like dock application using Haxe 3.1.3. I cant seem to work out how to make the main application window transparent (no titlebars, borders etc), as well as ignoring mouse events except on the icons themselves. Ideally no taskbar item either, just a system tray item.
I believe Haxe Windows target uses SDL, and am pretty sure that SDL can support this kind of behaviour? Im not sure how Neko target is compiled, or handles this... Is there some flags I can set in the Haxe application.xml or something like that? Or is this just not possible with the Haxe Windows or Neko targets?
EDIT
I Discovered that the Waxe haxelib, which can be compiled with Neko, has a bunch of flags in the Window.hx file - https://github.com/nmehost/waxe/blob/cd9739e007ed10918166588faf2339d623b22fc4/wx/Window.hx
These include such options as FRAME_NO_TASKBAR and BORDER_DOUBLE, which both work when passed as arguments to the wx.Frame.create() function in the Simple.hx Waxe sample project.
It also includes the flag TRANSPARENT_WINDOW, but this appears to do nothing. No idea why the other flags are working, but the TRANSPARENT_WINDOW flag doesnt.
In Openfl (it's openfl which uses sdl and a xml project), you can remove the window border with this in your application.xml:
<window borderless="true"/>
But I don't know a way to move the window without borders.
relevant discussion:
http://www.openfl.org/forums/#!/general:moving-borderless-windows

FileOpenDialog from vbScript custom action appears behind main dialog

I'm creating an installer at work that must open a file browser. There is no file browser in wix, so I built a custom vbscript action that uses the Shell.BrowseForFolder method. It's working fine, but the file dialog shows up behind the main wix window. Does anyone know a wix/vbscript approach I could take to solve this problem?
Locate the HWND for the MSI UI and pass this into Shell.BrowseForFolder. I see a few example solutions that use FindWindow("MsiDialogCloseClass", vbNullString). Be careful about launching UI from a custom action: you need to consider silent installs/repair/uninstall, etc to make sure you get it right in all cases.
It looks like you're trying to allow the user to pick a directory. MSI has native support for this. I reccomend you use that. For an example see http://wix.codeplex.com/SourceControl/latest#src/ext/UIExtension/wixlib/BrowseDlg.wxs.

How do I set the accessibility name for a QPushButton that just has an icon?

Qt version 4.8.1, building for Windows, I'm trying to get accessibility information to work correctly for some buttons I have.
I have a QPushButton in my main window, which has an icon, thusly:
m_restartBtn = new QPushButton();
QPixmap rpm(":/images/Restart32x32.png");
QIcon ricn(rpm);
m_restartBtn->setIcon(ricn);
m_restartBtn->setIconSize(rpm.rect().size());
// put it in a box in the main layout
QHBoxLayout *buttonBox = new QHBoxLayout;
ui->mainLayout->addLayout(buttonBox);
buttonBox->addWidget(m_restartBtn);
Now that button shows up correctly, and if I hook up the signals it works fine. But when I use the 'inspect.exe' (from the Win 7 SDK), I see that the button shows up, but has no name.
If I use setText instead of putting in an icon, the accessible name shows up correctly, but of course, I'm seeing text, not my icon. If I do both, then the accessible name works fine, but I get the text on screen, as one would expect.
I tried setObjectName and setWindowTitle just for laughs, and they of course didn't work.
Is there a proper way to set the accessible name for a QPushButton that only displays an icon?
My immediate goal is to remotely control the application for accessibility purposes. But I'd like the work to do double duty and get me full accessibility at the same time, so I don't have to do a separate effort later for accessibility.
You can use QWidget::setAccessibleName(const QString &name).
QPushButton *button = new QPushButton(this);
button->setAccessibleName("name");
Is this what you were looking for?

Why doesn't wxPerl draw my wxStaticBitmap when I run the program from a Windows shortcut?

I've made a wxPerl application which presents just a simple frame which only contains a wxMenuBar, wxPanel, wxTextCtrl and a wxStaticBitmap. The development and deployment platform is Windows XP and beyond.
The image is added to the form like this:
my $logoData = Wx::Bitmap->new(App::Resource::Images::getLogoPath(), wxBITMAP_TYPE_BMP);
my $logo = Wx::StaticBitmap->new($self, -1, $logoData);
I've had no problems displaying the image. I've made an installer with Inno Setup that adds a icon to the users' desktop. If the application gets started using that shortcut the window doesn't draw my wxStaticBitmap. Only when the application loses focus and some other window is being moved over it, only then will my wxStaticBitmap be drawn.
When starting the application from the start menu, quick start, or directly after compiling it with wxpar, or just with the perl interperter displays my wxStaticBitmap fine.
The only thing I've found is calling Refresh() and Update() on my wxFrame. After creating this wxFrame I call Show(1) and right after that Refresh() and Update(). But so far have had no luck with it.
wxStaticBitmap is derived from wxWindow, so it has both Update and UpdateWindowUI methods. What happens when you call one of those on $logo immediately after creating it?
Edit: I just tried it, and the Update* methods don't help. However, what does force it to repaint is to call SetBitmap after creating the object. Here's what I did:
my $bmp = Wx::Bitmap->new("./testcard.bmp", wxBITMAP_TYPE_BMP);
my $logo = Wx::StaticBitmap->new($frame, wxID_ANY, $bmp);
$logo->SetBitmap($bmp);
$frame is a Wx::Frame, and I just put a button in a sizer and the above code in its event handler callback.

Resources