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.
Related
I want to open a text file in linux using QProcess. I donot want to use QDesktopServices.
Is there any way to just point it to preferred editor and pass the name of the file as a parameter or any other way to open the text file ?
I display objects, some of which are files and folders in TTreeView, TListView and a few other custom controls.
When a folder is selected, I display its contents (files and folders) in TListViewand I use the Windows System Image List to assign an icon. I call SHGetFileInfoW to obtain an icon index. SHGetFileInfoW is also used to obtain the System Image List Handle:
SHFILEINFOW info ;
DWORD Flags = (SHGFI_SMALLICON | SHGFI_SYSICONINDEX | SHGFI_OVERLAYINDEX) // for instance
ImageList->Handle = SHGetFileInfoW( L"",
0,
&info,
sizeof(SHFILEINFOW),
Flags
) ;
My program also keeps its own ImageList with icons, since it displays more than just files and folders. In TreeView for instance a combination of 'other objects' and folder objects will be shown:
To keep folder icons consistent (same) between TreeView and ListView on different versions of the Windows OS, I copy the Windows System folder icon to my own ImageList during program start.
This way both TreeView and ListView use the same folder icon, and the icon is that of the OS the software is running on.
This has worked well for many years across many OS, from Win2K to W11. However I'd like to try the reverse approach now IF at all possible. I'd like to use my own folder icon in both ListView and TreeView. For TreeView this is not a problem, but for ListView it is an issue in every situation where files and folders are displayed together, since I use the Windows System Image List to display the file icons and hence also folder icons.
I can think of a workaround where I create the needed registry entries to register a very unique file extension that is associated with a folder icon in my executable. I could then use that for folders. But it's a workaround that may not always work perfectly if Windows doesn't refresh immediately etc.
So, the question, is it at all possible to add an icon to the System Image List during program execution ? Is there a Windows API call that does this ? If so I could use that Index then to display folder icons in ListView.
Yes and no.
First off, in Windows NT based systems, the system image list is per-process and is not a full copy of the real list. In Windows 95 it really was global. This means the design never intended for people to add extra HICONs on their own directly into the list.
While it is called the system image list, the only thing it stores are file type icons and the shell extension overlays, it is not a general icon list.
There are two ways to add icons to the list:
The common way is to use one of the shell functions (like SHGetFileInfo) to ask for information about a file path or extension.
The other way is to call Shell_GetCachedImageIndex. This function used to be undocumented and was only documented because of the DOJ trial.
My suggestion: Use your own custom imagelist with your custom images. In slot 0 place an empty icon that you draw on top of with custom draw (not owner-draw).
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
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
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.