Qt png file and window style [duplicate] - c++

This question already has answers here:
How do I add a background image to the QMainWindow?
(3 answers)
Closed 4 years ago.
Is there a way to change the style of the main window of the program from the standard style to the style of the png file (so that the window's appearance was like in the launcher of some online games)?
something like this (the best example from game GW2)

You don't do this sort of thing by making the image somehow spill out of the window, you do it by making a window large enough to hold the image and making the window background transparent. The Qt way to do this is using the Qt.WA_TranslucentBackground window flag (together with FramelessWindowHint).

ui->setupUi(this);
this->resize(1280,950);
setAttribute(Qt::WA_TranslucentBackground);
setWindowFlags(Qt::Window | Qt::FramelessWindowHint);
this->setStyleSheet("#centralWidget { "
" border-image: url(:/gw2.png);"
"}");
connect(ui->pushButton, SIGNAL(clicked(bool)), qApp,
SLOT(closeAllWindows()));
result

Related

Qt: How do I resize an image and maintain its proportions? [duplicate]

This question already has answers here:
How do I make an image resize to scale in Qt?
(2 answers)
Closed 4 years ago.
This Qt example shows how to resize an image contained in a dialog, so that when the dialog is resized, the image stretches accordingly.
How can I resize an image in the same way, without distorting it / keeping its proportions the same?
Of course if the width/height ratio of the dialog is different from the one of the image, I will get a "grey" area.
I found the Qt::KeepAspectRatio enum, but not the function to use it with.
Update: This is the code I am trying with:
QImage image(path);
QImage image2 = image.scaled(200, 200, Qt::KeepAspectRatio);
QLabel *plotImg = new QLabel;
plotImg->setScaledContents(true);
plotImg->setPixmap(QPixmap::fromImage(image2));
The image does not maintain a constant aspect ratio when the label is resized. And it looses resolution after the rescaling.
Use the QImage::scaled function.
QImage img("someimage.png");
QImage img2 = img.scaled(100, 100, Qt::KeepAspectRatio);
In case you need it for QPixmap, a function with the same name exists.

C++: How do I use SetLayeredWindowAttributes() only on a parent window? [duplicate]

This question already has answers here:
Closed 10 years ago.
Possible Duplicate:
Transparent window containing opaque text and buttons
I'm trying to manipulate an existing window with C++.
Basically, what I'm trying to do is set the parent window transparent via first setting its window style to WS_EX_LAYERED and then using SetLayeredWindowAttributes() with the right values.
The problem is that that will set the child windows to transparent also, which will make the whole program transparent (obviously a problem).
Any ideas?
EDIT Image demonstrating the problem:
As you might see, I set the taskbars window style to WS_EX_LAYERED, but for example the window MSTaskSwWClass (the window that has the running application icons) is also affected.
EDIT2 Tried UpdateLayeredWindow() with the exact same outcome.
As of http://msdn.microsoft.com/en-us/library/windows/desktop/ms633540%28v=vs.85%29.aspx
Windows 8: The WS_EX_LAYERED style is supported for top-level windows and child windows.
Previous Windows versions support WS_EX_LAYERED only for top-level windows.
So it will not set layered attribute to 'child' windows.
Show us screenshot and/or code.

How to make a Qt widget resizable [duplicate]

This question already has answers here:
Closed 10 years ago.
Possible Duplicate:
How can I add resizable widgets in Qt Creator?
I am using QTreeView and QListView and i want to make them to be sizable i.e. when i go the top end of the QTreeview the pointer should be transformed into a vertical arrow which allows me do a up resize by mouse drag and drop, a feature that is seen on many application nowadays.
How can be achieved this? Thank you.
You can put your widgets into a QSplitter.

Window background like title bar of windows 7 [duplicate]

This question already has an answer here:
Closed 10 years ago.
Possible Duplicate:
How to set Windows Forms Application (C++) to have an Aero/Glass background?
i want create a transparent window with WinApis with C++ in Windows 7 and i use VS2010 but i know how to make it transparent i can do that like this:
SetWindowLong(hWnd, GWL_EXSTYLE,GetWindowLong(hWnd, GWL_EXSTYLE) | WS_EX_LAYERED);
SetLayeredWindowAttributes(hWnd, 0, (255 * 70) / 100, LWA_ALPHA);
but i want a transparent window with transparency of title bars of normal windows of windows 7
sample http://ril.site11.com/photos/879ec4dfeaa4.png
This web page has a great tutorial: http://www.codeproject.com/Articles/15770/Vista-Goodies-in-C-Using-Glass-in-Your-UI
It show you how to make a certain portion of you windows transparent, how to add text to the transparent part, and more.

How can i add resize option in QMainWindow that is frameless window in QT? [duplicate]

This question already has answers here:
Closed 10 years ago.
Possible Duplicate:
Implement Resize option to Qt Frameless widget
I want to add resize option in my QMainWindows that is Frameless window, How can i add this feature to it?
please explain me with code
You can use QSizeGrip