Qt4 css - How to create file .QSS? - c++

I have a question.
How do I create in my project folder with a file. .QSS ?
At the option of creating new files do not have this extension!
I would be very grateful for the help.
Thank you.

Control+N
-> General
-> Chooose
In name write style.qss (you may also choose the directory)
Add to project, or SVN
Drink a coffie or beer

Just create it with a text editor like a notepad and save it with the .qss extension. I suggest to add it in your resource file.
You can load it using the following sample code
QFile file(":/qss/style.qss");
if(file.open(QFile::ReadOnly)) {
QString StyleSheet = QLatin1String(file.readAll());
qApp->setStyleSheet(StyleSheet);
}

Yeah, Qt Creator (I'm assuming that is what you are using) is a little lacking in this area. Just create the folder and file on your file system. Then, in Qt Creator, right click on the project and select Add Existing Files...

Related

How can I load an image to QPixmap without specifying the full path?

I'm using Qt Creator on Windows and trying to add an image to an icon.
The only way I can get it to work is by specifying the full path:
QPixmap newIcon("C:/Users/slipn/Documents/qt/projetos/exemplo/new.png");
newToolBarAction = toolbar->addAction(QIcon(newIcon), "New File");
I tried adding to the project as shown below:
The image and the code files are in the same directory. I have no clue of what path I should use to make it work. Any hints?
The problem you need to solve, is that your source path and the path where you build or maybe later even install your application are not the same. You need to bundle your image resource with your application, either by copying & installing it to your build/install, or by including it directly in your application binary.
The latter is your easiest bet with qmake. Installing files with qmake is (relatively) easy, but making your build result work without a separate make install step is a different thing.
Your easiest bet to solve both "running your build result directly" and "running the installed application" is to use the Qt Resource System.
Create a .qrc file with File > New File > Files and Classes > Qt > Qt Resource File, add a "prefix" (some name), add your image file there, and then use QPixmap newIcon(":/yourprefix/new.png") to access it in your application.

Cant open html resource file using ifstream::open - Visual Studio 2013

I am working on a project which requires me to open an HTML file and use its contents. I added it to Resource files but when I try to open it lie this:
std::ifstream templateFile;
templateFile.open("filename.html", std::ifstream::in);
The operation fails. I checked it by using templateFile.fail().
The above operation works when I provide the full path. The file lies in the project folder along with other files. I tried setting build action to content but still it doesnt work. Please Help.
Output directory, where your executable is compiled and put into differs from the source directory, where you create all your .cpp/.hpp files (I assume there is filename.html file). Local path filename.html is supposed to be local for your executable file, not the source file.
Read more about changing the output directory here: https://msdn.microsoft.com/en-us/library/ms165410.aspx
Under Configuration Properties / Debugging, see what your Working Directory is using the macros dialog box. Move your file into this folder.
Click the button shown in the figure. There, click either Edit or Browse. Browse will take you to the working directory. Edit will expose the link to open the macros box

Create folders/subfolders in an qt creator project

In my Qt Project, I want to create some subfolders like Audio or Video.
Something like this:
Project\Media
Project\Media\Audio
Project\Media\Audio\Video
How I can do this?
Is there an way to add a new folder in Qt Creator? Or do I need to create this manually via the explorer?
Currently the only way is to add or create file that is inside of the directory - then the directory will be also created in Projects view of the QtCreator. This is not really that bad, since you can create directory while adding a new class file to the project. When the file is added to the project, also all its parent directories will be reflected in the Projects view.
In qt you use mkdir
bool QDir::mkdir ( const QString & dirName ) const
which will create a subdirectory called (variable dirName)
You could also use cmake which allows you to generate makefiles for every platform you need, itsteand of writing them manually. See code examples here

How can I quickly rename an open file in WebStorm?

The documentation for WebStorm says if you want to rename a file, do it in the Project Tool window. The problem is that finding a file in the Project Tool window is a hassle. If you start typing there to find the file, it won't be able to locate it unless it is in an expanded folder.
How can I easily rename a file in WebStorm?
There is no way to rename file right from the editor. Try Navigate/Select In.../Project view to open a file in Project Tool window and then use Refactor/rename in its right-click menu
You can also enable the 'Autoscroll from source' Project tool window option to have the currently opened file auto-selected in the project tree
Also, Refactor/rename is available in file right-click menu in the Navigation Bar if it's enabled (View/Navigation bar)
In addition to that, You can use the shourtcut.
Click on the file in the project window & Press the buttton Shift+F6.
Right click on the file -> Refactor -> Rename or just use Shift+F6 as a shortcut and a dialog window will open up so you can change the name.

Creating shader files

I'm trying to learn some DirectX11 and I found good tutorial I'm following; however, for some reason the program crashes (The window appears but then a "not responding" message box appears), even though the build was successful. There were some thing about creating shader-files the author did specify on how to do, and i wanted to make sure I'm not making any errors there and that why my program crashes. So my questions are :
How do you create a shader files? In the tutorial we are using the extension .fx, but when you add a file in vs you can only choose from .h and .cpp . Do you only have to select .cpp and then add .fx in the end of the file name?
In what directory is the file suppose to be? (My files are currently in Source Files)
Yes that will work. Another way to do it is just to create a .txt then change the extention to .fx
(To show the file extention just open any folder, click on the organize button in the menu then choose "folder and search options". Uncheck the box "Hide extentions for know file types" under the tab view). After you change the extention you can open the document in notepad and write your code there
Go in to your project folder (in windows file system) and create a map called Data. Add you .fx file there. Then go to your solution explorer and rigth click on the project and choose properties. Go to Build Events -> Pre- Build Events. Add the line "xcopy /y /d "$(ProjectDir)Data" "$(OutDir)" in the box "Command Line". Now when building your project the files will be copied to the rigth place and you will be able to use your .fx file.
The .fx is associate it with an effect file. Meaning you have a combination of many shaders in the same file. Can you post some code of your render loop... also, are you calling the Present method?i.e.,
m_pSwapChain->Present(0, 0);