I am trying to set transparent background to a QWebView element.
+---------------------------+
| x | Window title | <<< Hidden borders and title bar
+---------------------------+ view->setWindowFlags(Qt::FramelessWindowHint);
| |
| ****************** |
| ********************<--|------- This is the HTML side (a rectangle with
| ****************** | rounded corners)
| <-|-- with transparent background that must
+---------------------------+ remain transparent for the desktop window
I searched about how can I set the transparent background for the webview and I found this code on all places:
QPalette pal = view->palette();
pal.setBrush(QPalette::Base, Qt::transparent);
view->page()->setPalette(pal);
view->setAttribute(Qt::WA_OpaquePaintEvent, false);
The code above doesn't work properly. This is how my window does look:
So, the issue is that the gray part MUST be transparent. How can I solve this?
I use the following code to undecorate the window.
view->setWindowFlags(Qt::FramelessWindowHint);
This works for me :
view->setStyleSheet("background:transparent");
view->setAttribute(Qt::WA_TranslucentBackground);
Related
I'm working on a Qt project, where I need to get the toolbar positions at run-time. I used QMainWindow::toolBarArea(QToolBar *toolbar) to get the current docked area of the toolbar. And then I can use that later with QMainWindow::addToolBar ( Qt::ToolBarArea area, QToolBar * toolbar ).
Let's assume I dock two toolbars in a single area (i.e. Bottom area), as below.
-----------------------------------
| Toolbar 1 |
-----------------------------------
| Toolbar 2 |
-----------------------------------
Then I save the area obtained from QMainWindow::toolBarArea, using QSettings and then load them back with QMainWindow::addToolBar , it loads as below.
-----------------------------------
| Toolbar 1 | Toolbar 2 |
-----------------------------------
Is there any way to re-dock them the original form, without using QMainWindow::saveState()?
I am trying to draw the intersection of one blue rectangle and one yellow rectangle
,-------------------,
| |
| Blue |
| ,-------+---------,
| | Green | |
'-----------+-------, Yellow |
|_________________|
using the methods CDC::Polygon and CDC::SetBkMode(TRANSPARENT)
but all I get is this :
,-------------------,
| |
| Blue |
| ,-------+---------,
| | |
'-----------+ Yellow |
|_________________|
Please give me a simple solution sticking with the MFC.
Thanks.
You cannot do this, regardless of whether SetBkMode is TRANSPARENT or OPAQUE since Polygon uses the currently selected brush to fill the polygon's interior. Instead what you should do is this:
Paint one rectangle first, paint the other rectangle next and then calculate the intersection of the two rectangles using CRect::IntersectRect (see http://msdn.microsoft.com/en-us/library/262w7389(v=vs.100).aspx).
If the intersection is non-empty, calculate the resulting "color blend" and create the appropriate brush and, using it, draw a third rectangle using.
For more information on how to blend the colors, check out Algorithm for Additive Color Mixing for RGB Values right here on StackOverflow.
I want to divide my window in the following manner
Build a vertical layout
-------------------------
| |
-------------------------
| |
| |
| |
| |
| |
| |
-------------------------
using QVBoxLayout. I want to maintain this ratio at all times. I will disabling re-sizing the window. Right now I have the following code.
QVBoxLayout baseLayout = new QVBoxLayout(this);
QLabel *widget = new QLabel(NULL);
widget->setStyleSheet("background-color: rgb(0, 39, 118)");
widget->setGeometry(0,0,400, 30);
widget->setPixmap(QPixmap("Logo-Large.gif"));
baseLayout->addWidget(widget);
...
This divides the window in equal parts. I can't use the form designer as I am building this UI dynamically.
Is there any property on QVBoxLayout that I can use to achieve this? Or Using this QVBoxLayout is simply wrong, if so please suggest an alternative.
Thanks and Regards,
Atul.
To make a QVBoxLayout keep a fixed ratio between two elememts, give them stretch parameters in addWidget. A stretch parameter of N that is x times another stretch parameter Y will make the corresponding widget have a height x times higher than the other widget.
If i have made rectangle then it is possible to add any text inside/onto that, like if there is a rectangle and I want to give a name to it for a case RECTANGLE, Something like this :
| |
| TEXT |
| |
| |
Thanks in advance:)
use a normal rectangle shape and add a decoration to it. A decoration can be places at any position.
see example: Figure Locator
Greetings
Andreas
Here is my layout:
I have a sizer that contains a grid (with a proportion of 1) and a ok/cancel button bar
The all thing is in a wxDialog
Here it is:
|||||||||||||||
| |
| GRID |
| |
| |
| |
|||||||||||||||
| OK CANCEL |
|||||||||||||||
The issue is that the grid contains too many row, and over flow the screen, so in the end I don't see the top part of the dialog. Is there a way, when calling Fit() on the dialog, to limit its height ?
I have tried stuff like this: SetSizeHints(-1,-1,-1,500); and SetMaxSize(500,500) but it did not worked.
Also I have tried to do that: this->SetSize(this->GetSize().GetX(), 500);, but since the vertical scroll bar appears on the grid, it is not wide enough and a horizontal scroll bar shows up.
EDIT
In the constructor I call wxGrid(parent, wxID_ANY, wxDefaultPosition, wxDefaultSize)
The easiest way to handle this is to use a grid of fixed size. If there are more rows than will fit, then a scroll bar will appear. You set the size you want in the constructor.
new wxGrid( this, IDC_grid, wxPoint(-1,-1),wxSize(igridxsize,igridysize));
If you want the size of the grid to adjust, e.g. when the user resizes the application window, things are a bit more complex. You need handle the window size event and change the grid size as appropriate.
Something along these lines:
myDialog::OnSize(wxSizeEvent& event);
{
wxSize dialogSize = event.GetSize();
myGrid->OnSize( wxSizeEvent(
dialogSize.GetWidth() * 0.9, dialogSize.GetHeight() * 0.7 ));
}