QFileDialog : how to set option to show content of folder in getExistingDirectory() - qt

I am using QFileDialog as
filename = QFileDialog::getExistingDirectory(this,"Select Image File: ",dataDir,0);
I want that I can check files inside folder before selecting it. function getExistingDirectory() is setting QFileDialog::ShowDirsOnly as a default option. I checked in docs there is no any option that do opposite of this. So I set last parameter 0. But now it is not using native dialog. I want to use native dialog with this. I have no clue how to do this cause no flag found in options for UseNativeDialog. Please help.

Try creating the file dialog on your own, something like:
QFileDialog dialog(this);
dialog.setFileMode(QFileDialog::Directory);
dialog.setViewMode(QFileDialog::Detail);
dialog.setDirectory(datadir);
dialog.exec();

The code by Sebastian should create a native dialog, unless you make a line such as:
dialog.setOption(QFileDialog::DontUseNativeDialog, true);
However, I have not been able to get this working under Windows, even though the documentation says that the QFileDialog::Directory option should display files by default. Not only that, but doing:
qDebug() << dir_selector.testOption(QFileDialog::ShowDirsOnly);
displays false on my system, indicating that there is probably a bug somewhere.

Related

Internationalize text in Qt Widgets

In Qt, I'm aware of the tr() function that you can use to internationalize string literals in the code. But how does it work for text that I have entered in a widget's properties, such as currentTabText in the screenshot below? Do I have to set such properties in code too and use the tr() function or is there an easier way to do that?
Nothing else is needed, Just make sure the attribute "translatable" is set to true(expand the currentTabText to see that)
By nothing else I mean nothing extra is needed apart from what is already being needed for tr() to work.
So I assume you already know about QTranslator , installTranslator(), lupdate and linguist etc.
Just open the drop down list of currentTabText, and make sure that translatable checkbox is checked.

Qt widget promotion error after reconstruct the folder of code

Class DCGraphicsView is a subclass of QGraphicsView, I put a QGraphicsView Widget on the UI file framework.ui. And the I promote that QGraphicsView Widget to DCGraphicsView. After clean, qmake and rebuild, everything is OK as expected.
But after I moved those code and ui file into a subfolder named ui, and modify the pro as well, use the same procedure as previous (clean, qmake and rebuild). An error message displayed when doing rebuild.
To figure out what causes this error, I cancel the promotion of QGraphicsView Widget, then no error pops out. If I put it back, the same error comes again. Confused.
error message as follows:
No rule to make target 'dcgraphicsview.h', needed by 'ui_framework.h'.Stop.
The "Header File" field in the promote dialog should contain the path of the header file relative to the base directory from which uic, Qt User Interface Compiler, is executed, so it should be "ui/dcgraphicsview.h".
You can change the path by double clicking on the path in the "Promoted Widgets" dialog.
I got the right solution. In pro file, use UI_DIR to specify the location of ui files. In unix like system, use unix:UI_DIR; and win32:UI_DIR for windows.

QtWebEngine doesn't support JavascriptCanCloseWindows

In QtWebkit, using QWebSettings class, I could enable like the permission to close the window using the JavaScript command window.close();:
setAttribute(QWebSettings::JavascriptCanCloseWindows, true);
But in QtWebEngine, such an attribute doesn't exist: http://doc.qt.io/qt-5/qwebenginesettings.html#WebAttribute-enum
How to allow JavaScript to close any QWebEngineView using window.close()?
Indeed, this attribute doesn't exist anymore in the Qt WebEngine.
However, you can close any views using the signal windowCloseRequested from your QWebEnginePage, and connecting it to a slot where you close the window. There is an example of use in the Demo Browser example, in the file webview.cpp:
connect(page(), &WebPage::windowCloseRequested, this, &QWidget::close);

Next and previous control button in winAPI to go to next page (c++)

I am creating an winAPI application in c++ I have a photo in preview pane and I want to create two buttons NEXT and PREVIOUS on clicking them I will go to the next page .
Could you please give me the idea how to do that in c++ ??
Do I need to use QT libraray or it can be done using the in built function of WinAPI like -
HWND hwndButton1 = CreateWindow(L"BUTTON",L"NEXT",WS_TABSTOP | WS_VISIBLE | WS_CHILD | BS_DEFPUSHBUTTON,550,800,100,30,m_hwndPreview,(HMENU)buttonid1,(HINSTANCE)GetWindowLong(m_hwndPreview, -6),NULL);
HWND hwndButton2 = CreateWindow(L"BUTTON",L"PREVIOUS",WS_TABSTOP | WS_VISIBLE | WS_CHILD | BS_DEFPUSHBUTTON,650,800,100,30,m_hwndPreview,(HMENU)buttonid2,(HINSTANCE)GetWindowLong(m_hwndPreview, -6),NULL);
and then using WM_COMMAND for both the button clicks.
Am I going right?
I just want my API application work like a .pdf extension file...as in PDF files we have up and down arrow and on clicking upon them we can go to the next page..In winAPIc++ I couldn't find any such arrow function.. please tell me if there is any such arrow up/down function present to go to next page (because I am very less interested in creating NEXT and PREVIOUS button using createwindow function.. It looks odd).
You have not mentioned what tools you are using, so we don't know if you have a resouce editor. You should research that in a forum appropriate for the tools. If you think writing one line of code to create a button is "very complicated" then you need a better tool.
If you do not want the buttons to appear on top of the picture then you need another place to put them. One common possibility is a toolbar. It is a strip for buttons along the top or bottom of the main window:
http://msdn.microsoft.com/en-us/library/windows/desktop/bb760435(v=vs.85).aspx
With a resource editor you can draw an arrow on the button. Without a resource editor you can set the button text to a unicode arrow:
SetWindowText(hwndButton1, L"\x25bc"); // down arrow, use 25b2 for up arrow
Most buttons (and other controls) are created using a resource editor, placing the controls on a dialog template or a toolbar resource. If you do that Windows will create the buttons when you create the dialog or toolbar. This method is much preferred because Windows will adjust the size of the buttons as required for the screen settings in use.
If you can't do that you must use CreateWindow as you are doing.
Finally it is done.. I have created the buttons neither using Qt or nor using any createWindowEx..The best and easy approach to follow is resource editor ...just put some button on dialog and use IDD_MAINDIALOG (in my case)
m_hwndPreview = CreateDialogParam( g_hInst,MAKEINTRESOURCE(IDD_MAINDIALOG), m_hwndParent,(DLGPROC)DialogProc, (LPARAM)this);
and then
BOOL CALLBACK AMEPreviewHandler::DialogProc(HWND m_hwndPreview, UINT Umsg, WPARAM wParam, LPARAM lParam)
{
switch(Umsg) // handle these messages
{ .........
}
....
}
and thats done. Very easy task.

How to suppress Flash migration warnings (1090)

In Flash Professional CS4, I get "migration issue" warnings when I use mouse/keyboard input handler names such as onMouseDown, onKeyUp, etc., even though I have added event listeners for them. These names are perfectly legal for functions, but since these were automatically fired in ActionScript 2.0, we are now (albeit sensibly) warned that their use is no longer automatic in AS3.
I understand the purpose of the warnings, but they aren't useful for me. I want to suppress these warnings, but without suppressing any other warnings, which I generally do find useful.
E.g., when I use code like this:
/** #constructor */
public function MyClass() {
addEventListener(MouseEvent.MOUSE_DOWN, onMouseDown);
}
protected function onMouseDown(e:MouseEvent):void {
I get an annoying warning like this:
Warning: 1090: Migration issue: The onMouseDown event handler is not triggered automatically by Flash Player at run time in ActionScript 3.0. You must first register this handler for the event using addEventListener ( 'mouseDown', callback_handler).
There are flex compiler (mxmlc) flags (and a Flash Pro setting) which can suppress actionscript warnings, or all warnings, but I don't want that. That's too general.
Ideally I could suppress a specific error/warning number (Warning #1090).
Edit: I've found more "advanced" compiler flags with mxmlc -help advanced, which look promising. Specifically, the following seem like likely candidates:
warn-deprecated-event-handler-error
warn-deprecated-function-error
warn-deprecated-property-error
How do I get Flash to use these?
Edit 2: I found a flex-info.xml style document in the Flash User Data dir.
[userdatafolder]/Adobe/Flash CS4/en/Configuration/ActionScript 3.0/FlexInfo.xml
However, this file contains a disappointing comment: <!-- Flash does not support most flex-config options. -->, and doesn't seem to respond to my directives even after restarting flash.
This is getting sad.
Edit 3: Found an issue "Erroneous, annoying "Migration issue" warnings" on Adobe bug tracker. A fix is confirmed for the Flex SDK, but no mention of Flash...
You can if you edit EnabledWarnings.xml in $Flash/$LOCALE/Configuration/Actionscript 3.0/EnabledWarnings.xml, where $Flash is the path to Flash inside your Applications/Program Files folder and $LOCALE is your language.
e.g.
/Applications/Adobe Flash CS4/en/Configuration/ActionScript 3.0/EnabledWarnings.xml
You will need to edit line 29, setting the enabled attribute to false for warning with id 1090:
<warning id="1090" enabled="false" label="kWarning_DepricatedEventHandlerError">EventHandler was not added as a listener.</warning>
Quick sidenote:
"Flash Builder (CS4)" is a confusing term. After Flex Builder 3, Flex Builder got renamed to Flash Builder, there is no Flash Builder CS4. The regular Flash IDE is known as Flash Professional/Flash Professional CS4, this was to avoid confusion between products with similar names: Flash Catalyst, Flash Builder(was Flex Builder), Flash Professional. Obviously it doesn't always work that great :)
What about changing the name of the function being called from onMouseDown to handlerOnMouseDown. Would it solve the issue?
Are you using Flex Builder?
If so, go to Project -> Properties -> Flex Compiler. There you can add arguments to the compiler.
Why are you overriding that? It never existed in the first place. The error message is actually telling you something useful. Don't suppress it.
If you want to create an event handler called onMouseDown, try something like
private function onMouseDown(e:MouseEvent) : void {
// statements
}
I agree with the previous post; the message is trying to tell you that you need to register that event handler. Just adding a method called onMouseDown() won't do it. What you need to do is to add something like
addEventListener(MouseEvent.MOUSE_DOWN, onMouseDown);
in either your constructor or maybe in the parent component.
You can filter out these warnings using Flash Builder's problems filtering capability:
open problems view
on the right click on the small triangle that opens a drop-down menu
select Configure Contents...
on the left side, create a new configuration, name it as you wish
on the right side adjust its settings:
Scope: On any element in the same project (or anything you want)
Description: choose doesn't contain and type in Migration issue (this will filter out warnings with migration issue in the description)
choose at least Flex problems
You can combine predefined and custom configurations by selecting more then one on the left side.

Resources