Qclipboard how to get the destination path - c++

I'm currently developing an app which as a kind of file browser. I'm trying to move some files from my app to any other location using drag and drop.
I do not find how the clipboard is able to determine the copy. Currently, when moving a file from my app to the finder, a text clipping file is created to the destination path I have selected. I need to catch this information. I'm expecting to find it in the clipboard as it seems that clipboard is able to create a file at the right location.
I have tried to use the QClipboard class as the clipboard create a txt file in the selected detination path. As I have a file to transfer, I need to catch the destination path
Any idea on how to retrieve the destination path ? CLipboard class seems more easy as the clipboard is able to copy/create a file at the rigth location. Any idea on how to do it ?
I have created:
QWidget *pWin = QApplication::activeWindow();
QClipboard *clipboard = QApplication::clipboard();
But no way to find methods to extract the latest highlighted finder folder for example but clipboard is supposed to be aware of.
Seb

Related

Non native Qt file dialog add system explorer bookmarks

In the application that I work on, I need to use a QFileDialog that is non-native (QFileDialog::DontUseNativeDialog) because we need to add some custom logic in the folder selection (like if the folder contains a file, this part is out of the scope of this question). I can add the desired paths on the side bar by using:
QFileDialog *fd = new QFileDialog(parent, caption, updateLastAccessedDir(dir));
fd->setOptions(options | QFileDialog::DontUseNativeDialog);
QFileInfoList drives = QDir::drives();
for (auto d : drives)
fd->sidebarUrls()->append(QUrl::fromLocalFile(d.path()));
fd->sidebarUrls()->append(QUrl::fromLocalFile(QStandardPaths::writableLocation(QStandardPaths::HomeLocation)));
fd->sidebarUrls()->append(QUrl::fromLocalFile(QStandardPaths::writableLocation(QStandardPaths::DocumentsLocation)));
fd->sidebarUrls()->append(QUrl::fromLocalFile(QStandardPaths::writableLocation(QStandardPaths::DesktopLocation)));
I want to be able to also add the bookmarked locations that the user has in the native file explorer. However, I do not know how to get the list of these paths.
Is there any way of getting the list of bookmarked paths in the native file explorer in c++? This is a Ubuntu and Windows application so it would be perfect if the solution is not OS-dependent (which I'm afraid will not be possible).

Having an image in a qt window without having the image file itself as source

I have a window in Qt with an image (logo). For this small program to function the image file (png or jpeg) must be accessed from the exe-file. I wish to have the image saved somewhere as an array or else in some other format like cpp or h or else. Is this with Qt possible?
A better way of doing this would be using the Qt resources system.
You basically specify the resources to embed in a .qrc file and you can afterwards use them by providing the resource path
cutAct = new QAction(QIcon(":/images/cut.png"), tr("Cu&t"), this);

Qt c++ : Dynamic GUI from multiple .ui files

I have been developing an GUI application in Qt. In which i need to load the GUI from different form files (.ui).
Please be patient as I am going to write a lot of things.
The idea is to keep my application completely flexible that the user can change the interface by simply editing .ui files and there will be no need to modify the source code for new element added to .ui files.
I am also trying to divide the software in multiple layers. (I'll try to clarify below.)
For example: (Please see the attached image. I have merged all the images in single file because my account is not authorised to add more than two images.)
I have the main window as show in image (Main)
The first.ui file contains primary widget which is tab widget and looks like as shown in image (First)
The second.ui file contains second widget which I need to add into the tab widget.
the second form looks like as shown in image (Second)
At the end the complete interface will look something like as shown in image (Final) Image Link Here
In the code I have done the following:
/*
Created a Main Window with menubar.
The menubar has an action to select and open a first.ui file.
The File opened is loaded by QUiLoader loader.
First.ui file containes a QTabWidget with two tabs and a label.
In label, i have given a path to another file second.ui
loader loads the opened file and returns the QWidget
The returned QWidget has been set as a CenntralWidget in MainWindow.
Then I have read the first.ui file to find the text given in label (which is the path to another file second.ui).
Once I have obtained that path, I have loaded the second.ui file using loader.
This file contais a widget having form layout and few buttons.
Now I am trying to add this obtained widget to the Tab loaded from previous file.
CASE 1:
I successfully managed to do it by using:
selectedTab->layout()->addWidget(otherWidgetObainedFromSecondFile);
but in this case, the problem is that, I cannot access the element of form and buttons.
That is, The buttons and form fields doesnt look like an active element.
They just look like a snapshot fixed in the tab.
CASE 2:
So, in contrary I decided not to directly add the widget to tab.
But i created another MainWindow, set the second widget as centralWidget to this new main window.
And then added this mainwindow to tab.
but it also gave me the same result.
*/
Please suggest me a solution.
I am open to different suggestions but I want to keep the idea same that is the GUI has to remain in layered form (loads from multiple ui files)
I will really appreciate your help.
You can use QFormBuilder for this.
Assuming your Tab Widget is named TabPane
QFormBuilder loader;
QFile file(":second.ui");
file.open(QFile::ReadOnly);
QWidget *pane=loader.load(&file,this);
file.close();
qDeleteAll(ui->TabPane->findChildren<QWidget *>(QString(),Qt::FindDirectChildrenOnly)); //remove any existing child widgets from TabPane
ui->TabPane->layout()->addWidget(pane);
If I understand you correctly you have to use addTab method of QTabWidget

C++ SaveFileDialog file icon

In C++ using Windows OS, I am using a System::Windows::Forms::SaveFileDialog object to choose a file in which some data will be serialized. I would like to know if it is possible to set a custom icon to the file that will be created. I have set the Filter property to "[ProjectName] file (.hys)|.hys" and the file icon is blank, but I would like to assign a custom icon to it.

Windows: open a named document

I'm trying to extend an existing app called Drax which edits the metadata of MP4 movie files.. I want to be able to drag-n-drop files onto it, which it does not support. I've gotten far enough to be able to decode the "clipboard" data when it is dropped, and filter to accept only the file (extensions) that I can handle. (Like so but I know next to no winapi/C++ so it's all cargo-culted.)
But now I want to trigger opening the document, whose (file) name I have in a TCHAR. And I'm stuck. How do I trigger the same sort of action the File>Open dialog would, when I know the name of the file from a drag/drop operation?
Normally, the File -> Open dialog does not do anything but allow the user to choose a file name. It then returns this file name to you, the programmer, to do something with.
But, in this case, you're modifying an existing application, so that code has already been written. To find it, you need to search for the method(s) that display the File -> Open dialog. See what they do with the file name(s) returned by the Open dialog.
All the logic for opening the file is very likely to be crammed into the same method as the one that displays the File -> Open dialog. If so, what I would do is refactor the code, so that you have a separate method like
void OpenFile(CString pszFileName, /* other important parameters */)
{
// ...
}
that handles opening the file, specified by a string containing its full path. You will call this method once you get the file name from the File -> Open dialog, and also from elsewhere, like after you get the file name from a drag-drop operation.