Qt widget promotion error after reconstruct the folder of code - qt

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.

Related

How to upload a file Using Robot framework?

i want to upload a pic using robot framework into this :
I tried this :
Add PJ
Scroll Element Into View xpath://div[#class='drop-zone text-center']
Choose File xpath://label[#class='label-dropZone'] ..\Resources/Robot-framework-logo.png
but i'm getting this error :
ElementNotInteractableException: Message: element not interactable
What the underlying Selenium function behind Choose File does is to enter the text you give to it (that's the path to the local file), in an <input> element. These elements are the ones defined in the HTML standards for uploading files.
In "fancier" upload UI these input are hidden - the user doesn't see the file path, but sees explanatory text "choose a file here or drag&drop it", with pleasing formatting. This is the case with your example - and targeting that <label>, Selenium has failed by saying it is not interactable - one cannot "type" on it; it does need an <input>.
You may/should try to find the <input> in the form, though hidden, and target it. Sometimes that is not possible though - there might be JS code preventing you to change it; so the success rate is varying.

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

How to build widgets from any .ui files created by QtDesigner

I would like to make something like GUI creator which takes an ui file and creates widgets in it, and show in a window.
So I have created a button on click I use QFileDialog to get a file.
And then I would like to use the ui file from QFileDialog to create that gui/widgets and show in a window.
I have tried QFormbuilder, but it always gives me compile error “undefined reference to `QFormBuilder::QFormBuilder()’”
Is there a way to do it in qt5?
Any help appreciated
From documentation of QUiLoader:
QUiLoader loader;
QFile file(":/forms/myform.ui");
file.open(QFile::ReadOnly);
QWidget *myWidget = loader.load(&file, this);
file.close();
I have solved the problem.
Actually I was missing QFormbuilder module in my .pro file. So I have just added them, and it is working fine.

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

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.

global event catch for QEventfilter class

I want to add a help webpage for my Qt Application. The user can use the Qt::WhatsThis "tooltip" to have a explanation about the topic and a URL to a webpage. I edit the WhatsthisTooltips with the Qt Designer and have it language indepentend.
Now I create a "LinkFilter" class for filtering, install it in the viewclass and react on the QEvent::WhatsThisClicked event. This works fine.
Now i would catch every QEvent::WhatsThisClicked in my application, but i looks really messy to install it on really every dialog/view/action/widget. This there some kind of global eventHandler, were I can install my "LinkEvent"class? There must be a nice Qt style way for solving this.
For installing the EventFilter I strongly followed this video-tutorial http://youtu.be/DHgbYxpZkbg
http://qt-project.org/doc/qt-4.8/qapplication.html#notify
Essentially you need to subclass QApplication and override this function. Then you can check if it's the type of event you're looking for and act accordingly.

Resources