Unable to create a transparent QFrame - transparency

I want to create QWidget which has no background; and I want to add a transparent QFrame to it. This is my code:
QWidget *change_impl_win = new QWidget();
QHBoxLayout *mainLayout = new QHBoxLayout(change_impl_win);
QVBoxLayout *vbox_l = new QVBoxLayout();
QFrame *back_frame = new QFrame();
back_frame->setBackgroundColor(QColor(125, 125, 125, 125));
QHBoxLayout *frame_hbox = new QHBoxLayout(back_frame);
frame_hbox->addLayout(vbox_l);
mainLayout->addWidget(back_frame);
QGroupBox *newImplant = new QGroupBox("");
QGridLayout *layoutNewImplant = new QGridLayout;
newImplant->setLayout(layoutNewImplant);
vbox_l->addWidget(newImplant);
QRadioButton *cb_ob_rb = new QRadioButton("Up", change_impl_win);
QRadioButton *cb_un_rb = new QRadioButton("Down", change_impl_win);
layoutNewImplant->addWidget(cb_ob_rb);
layoutNewImplant->addWidget(cb_un_rb);
QLabel* lengthLabel = new QLabel("Length:");
QSpinBox *cb_implantLength = new QSpinBox;
cb_implantLength->setRange(1, 20);
cb_implantLength->setSingleStep(1);
cb_implantLength->setSuffix(" mm");
layoutNewImplant->addWidget(lengthLabel, 2, 0);
layoutNewImplant->addWidget(cb_implantLength, 2, 1);
QLabel* diameterLabel = new QLabel("Diameter:");
QSpinBox *cb_implantDiameter = new QSpinBox;
cb_implantDiameter->setRange(1, 20);
cb_implantDiameter->setSingleStep(1);
cb_implantDiameter->setSuffix(" mm");
layoutNewImplant->addWidget(diameterLabel, 3, 0);
layoutNewImplant->addWidget(cb_implantDiameter, 3, 1);
QPushButton *cb_apply_prop = new QPushButton();
cb_apply_prop->setText("Apply");
cb_apply_prop->setGeometry(400, 0, 200, 40);
cb_apply_prop->setFont(QFont("Charter",13));
cb_apply_prop->setAutoFillBackground(true);
frame_hbox->addWidget(cb_apply_prop);
change_impl_win->setAttribute(Qt::WA_TranslucentBackground);
change_impl_win->setWindowFlags(Qt::FramelessWindowHint | Qt::WindowStaysOnTopHint);
change_impl_win->show();
But, I can't see the transparent QFrame. I am seeing only controls added to QWidget with no background. Please tell me where I made mistake. Thank you.

Related

Segmentation Fault in vkCmdBlitImage

There is a segmentation fault in vkCmdBlitImage. According to Valgrind, it is an invalid read of size 8 with the address being 0x48. Disabling layers does not fix the problem.
The driver used is the Nvidia Linux driver version 364.19. The GPU is a GeForce GTX 970.
Relevant code:
VkImageCreateInfo img_info;
img_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
img_info.pNext = NULL;
img_info.flags = 0;
img_info.imageType = VK_IMAGE_TYPE_2D;
img_info.format = VK_FORMAT_R8G8B8A8_UNORM;
img_info.extent = (VkExtent3D){info.width, info.height, 1};
img_info.mipLevels = 1;
img_info.arrayLayers = 1;
img_info.samples = VK_SAMPLE_COUNT_1_BIT;
img_info.tiling = VK_IMAGE_TILING_LINEAR;
img_info.usage = VK_IMAGE_USAGE_TRANSFER_SRC_BIT;
img_info.sharingMode = VK_SHARING_MODE_EXCLUSIVE;
img_info.queueFamilyIndexCount = 0;
img_info.pQueueFamilyIndices = NULL;
img_info.initialLayout = VK_IMAGE_LAYOUT_PREINITIALIZED;
VkImage src_image;
VKR(vkCreateImage(info.device, &img_info, NULL, &src_image));
VkMemoryRequirements src_req;
vkGetImageMemoryRequirements(info.device, src_image, &src_req);
VkDeviceMemory src_mem = create_memory(info.physical_device, info.device,
src_req.memoryTypeBits, src_req.size,
true); //The true makes it create host-visible memory.
vkBindImageMemory(info.device, src_image, src_mem, 0);
VkImageSubresource src_subres;
src_subres.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
src_subres.mipLevel = 0;
src_subres.arrayLayer = 0;
VkSubresourceLayout src_subres_layout;
vkGetImageSubresourceLayout(info.device, src_image, &src_subres, &src_subres_layout);
uint8_t* src_data = NULL;
VKR(vkMapMemory(info.device, src_mem, src_subres_layout.offset, src_subres_layout.rowPitch*info.height, 0, (void**)&src_data));
//Code that initialized src_data
VkMappedMemoryRange range;
range.sType = VK_STRUCTURE_TYPE_MAPPED_MEMORY_RANGE;
range.pNext = NULL;
range.memory = src_mem;
range.offset = src_subres_layout.offset;
range.size = src_subres_layout.rowPitch * info.height;
VKR(vkFlushMappedMemoryRanges(info.device, 1, &range));
vkUnmapMemory(info.device, src_mem);
VkCommandBufferAllocateInfo alloc_info;
alloc_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_ALLOCATE_INFO;
alloc_info.pNext = NULL;
alloc_info.commandPool = info.cmd_pool;
alloc_info.level = VK_COMMAND_BUFFER_LEVEL_PRIMARY;
alloc_info.commandBufferCount = 1;
VkCommandBuffer cmd_buf;
VKR(vkAllocateCommandBuffers(info.device, &alloc_info, &cmd_buf));
VkCommandBufferBeginInfo begin_cmd_buf_info;
begin_cmd_buf_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
begin_cmd_buf_info.pNext = NULL;
begin_cmd_buf_info.flags = VK_COMMAND_BUFFER_USAGE_ONE_TIME_SUBMIT_BIT;
begin_cmd_buf_info.pInheritanceInfo = NULL;
vkBeginCommandBuffer(cmd_buf, &begin_cmd_buf_info);
image_barrier(VK_IMAGE_ASPECT_COLOR_BIT, cmd_buf, VK_ACCESS_HOST_WRITE_BIT,
VK_ACCESS_TRANSFER_READ_BIT, VK_IMAGE_LAYOUT_PREINITIALIZED,
VK_IMAGE_LAYOUT_TRANSFER_SRC_OPTIMAL, VK_PIPELINE_STAGE_HOST_BIT,
VK_PIPELINE_STAGE_TRANSFER_BIT, src_image);
image_barrier(VK_IMAGE_ASPECT_COLOR_BIT, cmd_buf, info.dst_img_access,
VK_ACCESS_TRANSFER_WRITE_BIT, info.dst_img_layout,
VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL, VK_PIPELINE_STAGE_TOP_OF_PIPE_BIT,
VK_PIPELINE_STAGE_TRANSFER_BIT, info.dst_image);
VkImageBlit region;
region.srcSubresource = (VkImageSubresourceLayers){VK_IMAGE_ASPECT_COLOR_BIT, 0, 0, 1};
region.srcOffsets[0] = (VkOffset3D){0, 0, 0};
region.srcOffsets[1] = (VkOffset3D){info.width, info.height, 1};
region.dstSubresource = (VkImageSubresourceLayers){VK_IMAGE_ASPECT_COLOR_BIT, 0, 0, 1};
region.dstOffsets[0] = (VkOffset3D){0, 0, 0};
region.dstOffsets[1] = (VkOffset3D){info.width, info.height, 1};
vkCmdBlitImage(cmd_buf, src_image, VK_IMAGE_LAYOUT_TRANSFER_SRC_OPTIMAL, info.dst_image, VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL, 1, &region, VK_FILTER_NEAREST);
vkEndCommandBuffer(cmd_buf);
The rest of the code is found at https://gitlab.com/pendingchaos/WIP29/tree/00f348f2ef588e5f724fcb1f695e7692128cac4c/src.
Cut down output of vulkaninfo can be found at http://pastebin.com/JaHqCy98.
Your synchronization seems improper for the jorb. They discard your preinitialized Image and do no synchronization (due to the dst=BOTTOM).
Let me put together something that should work just fine with your computationaly demanding 4x4 Image processing:
image_barrier( VK_IMAGE_ASPECT_COLOR_BIT, cmd_buf,
VK_ACCESS_HOST_WRITE_BIT, VK_ACCESS_TRANSFER_READ_BIT,
VK_IMAGE_LAYOUT_PREINITIALIZED, VK_IMAGE_LAYOUT_TRANSFER_SRC_OPTIMAL,
VK_PIPELINE_STAGE_HOST_BIT, VK_PIPELINE_STAGE_TRANSFER_BIT,
src_image);
image_barrier( VK_IMAGE_ASPECT_COLOR_BIT, cmd_buf,
info.dst_img_access, VK_ACCESS_TRANSFER_WRITE_BIT,
info.dst_img_layout, VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL,
VK_PIPELINE_STAGE_ALL_COMMANDS_BIT, VK_PIPELINE_STAGE_TRANSFER_BIT,
info.dst_image);
BTW:
the amount should be VkDeviceSize not size_t in createMemory()
vkBindImageMemory(), vkBeginCommandBuffer() and vkEndCommandBuffer() return and should perhaps be in your VKR
If you rewrite whole aspect of the image, you can use src=LAYOUT_UNDEFINED to discard the old data (more efficient!)

Xamarin Forms Grid in a TableView

I am creating a financial app and need to show a table with section headers and many grids.
In the attached screenshot I am almost there. I need the first column to Left align (start) and the rows to be about double their default height.
var content = new TableView
{
Intent = TableIntent.Data,
Root = new TableRoot("Performance"),
BackgroundColor = Color.Green
};
content.Root.Add(GetTableSection("Monthly", Model.Monthly);
.................
private TableSection GetTableSection(string title, List<PerformanceRow> performanceRows)
{
TableSection section = new TableSection()
{
Title = title
};
foreach (var row in performanceRows)
{
Grid grid = new Grid
{
VerticalOptions = LayoutOptions.FillAndExpand,
HeightRequest = 100, //?????????
BackgroundColor = Color.Red,
ColumnDefinitions =
{
new ColumnDefinition {Width = new GridLength(.3, GridUnitType.Star)},
new ColumnDefinition {Width = new GridLength(.3, GridUnitType.Star)},
new ColumnDefinition {Width = new GridLength(.3, GridUnitType.Star)},
}
};
//First Row
grid.Children.Add(new Label {Text = row.Title, HorizontalOptions = LayoutOptions.Start}, 1, 0);
grid.Children.Add(new Label {Text = "Market Value"}, 2, 0);
grid.Children.Add(new Label {Text = row.MarketValue.ToString("C"), HorizontalOptions = LayoutOptions.End}, 3, 0);
//Second Row
grid.Children.Add(new Label {Text = " "}, 1, 1);
grid.Children.Add(new Label {Text = "Return"}, 2, 1);
grid.Children.Add(new Label {Text = row.ReturnRate.ToString("C"), HorizontalOptions = LayoutOptions.End}, 3, 1);
section.Add(new ViewCell()
{
View = grid,
Height = 100 //??????????
});
}
return section;
}
This worked:
Set the UnevenRows to true for the tableview, then the table intent to rows

Corona SDK crash when trying to combine filters/effects

I am trying to create new effect by combining existing ones and Corona Simulator crashes.
Here is my code
graphics.defineEffect({
language = "glsl",
category = "filter",
name = "myEffect",
graph = {
gray = { effect = "filter.grayscale", input1 = "paint1" },
--final = { effect = "filter.contrast", input1 = "gray" },
},
output = "gray"
});
local rect = display.newRect(100, 100, 100, 100);
rect:setFillColor(1, 0, 0);
rect.fill.effect = "filter.myEffect";
Also question about arguments for filter. How can I specify arguments for filter contrast in this sample?
Thank you
This was recently bringing trouble to me too. I found it to be solvable by declaring the graph definitions of the effects in a nodes table.
I included the solution and corrected syntax below.
graphics.defineEffect({
language = "glsl",
category = "filter",
name = "myEffect",
graph = {
nodes = {
gray = { effect = "filter.grayscale", input1 = "paint1" }
--final = { effect = "filter.contrast", input1 = "gray" },
},
output = "gray"
}
})
local rect = display.newRect(100, 100, 100, 100);
rect:setFillColor(1, 0, 0);
rect.fill.effect = "filter.myEffect";
Regarding the contrast questions, excuse me if I misunderstood but this should be a viable solution
graphics.defineEffect({
language = "glsl",
category = "filter",
name = "myEffect",
graph = {
nodes = {
gray = { effect = "filter.grayscale", input1 = "paint1" },
final = { effect = "filter.contrast", input1 = "gray" }
},
output = "final"
}
})
local rect = display.newRect(100, 100, 100, 100);
rect:setFillColor(1, 0, 0);
rect.fill.effect = "filter.myEffect";
rect.fill.effect.final.contrast = 2
A good introduction to this is Tutorial: Multi-Pass Shaders in Graphics 2.0 by Bryan Smith

DirectX texture saves as empty bitmap

I have a DirectX rendering that works perfectly when I render to the screen:
var DxDevice = D3D.D3DDevice.CreateDeviceAndSwapChain(host.Handle);
...
var DxFinalRenderTexture = DxDevice.SwapChain.GetBuffer<D3D.Texture2D>(0);
var DxFinalRenderTarget = DxDevice.CreateRenderTargetView(DxFinalRenderTexture);
DxDevice.OM.RenderTargets = new D3D.OutputMergerRenderTargets(new D3D.RenderTargetView[] { DxFinalRenderTarget }, null);
DxTechnique.GetPassByIndex(0).Apply();
DxDevice.Draw(4, 0);
DxDevice.SwapChain.Present(0, GX.PresentOptions.None);
(input layout and vertex buffers are omitted here because, as I said, the rendering works as expected to the screen).
When I change it slightly to use a different render target rather than the screen:
var description = new D3D.Texture2DDescription() {
Width = 1024,
Height = 1024,
ArraySize = 1,
BindingOptions = D3D.BindingOptions.RenderTarget | D3D.BindingOptions.ShaderResource,
CpuAccessOptions = D3D.CpuAccessOptions.None,
Format = DX.Graphics.Format.B8G8R8A8UNorm,
MipLevels = 1,
MiscellaneousResourceOptions = D3D.MiscellaneousResourceOptions.None,
SampleDescription = new DX.Graphics.SampleDescription(1, 0),
Usage = D3D.Usage.Default
};
var DxFinalRenderTexture = DxDevice.CreateTexture2D(description);
var description2 = new D3D.RenderTargetViewDescription() {
Format = description.Format,
ViewDimension = D3D.RenderTargetViewDimension.Texture2D,
Texture2D = new D3D.Texture2DRenderTargetView() { MipSlice = 0 }
};
var DxFinalRenderTarget = DxDevice.CreateRenderTargetView(DxFinalRenderTexture, description2);
and finally save the texture by duly copying it to a staging resource and mapping the latter:
private WriteableBitmap GetTexture(D3D.Texture2D texture) {
var description = new D3D.Texture2DDescription() {
Width = 1024,
Height = 1024,
ArraySize = 1,
BindingOptions = D3D.BindingOptions.None,
CpuAccessOptions = D3D.CpuAccessOptions.Read,
Format = DX.Graphics.Format.B8G8R8A8UNorm,
MipLevels = 1,
MiscellaneousResourceOptions = D3D.MiscellaneousResourceOptions.None,
SampleDescription = new DX.Graphics.SampleDescription(1, 0),
Usage = D3D.Usage.Staging
};
var texture2 = DxDevice.CreateTexture2D(description);
DxDevice.CopyResource(texture2, texture);
var texmap = texture2.Map(0, D3D.Map.Read, D3D.MapOptions.None);
var bitmap = new WriteableBitmap(1024, 1024, 96, 96, PixelFormats.Pbgra32, null);
bitmap.Lock();
bitmap.WritePixels(new Int32Rect(0, 0, 1024, 1024), texmap.Data, 1024 * 1024 * 4, 1024 * 4);
bitmap.Unlock();
texture2.Unmap(0);
return bitmap;
}
the resulting bitmap will be completely empty. There are no errors either in compilation or during the run, just the emptiness.
It might also be worth noting that I don't need repeatedly rendered frames, just a single bitmap created, so there are no performance issues involved. I'd be happy to do away with the screen rendering completely and render to a final bitmap that I can use later.

Microsoft charts: transparency

I want a chart with transparent background, and therefore PNG seems a good choice. But when I set transparent background, the quality of the axis labels falls dramatically. How do I fix this? See the following code. As it stands, the chart has a transparent background, as I want, but the text quality is atrocious. If I comment out the two "Color.Transparent" settings, then the text quality is nice, but the background is not transparent.
How do I get transparency and nice text?
public static void Main(string[] args)
{
Chart c = new Chart();
c.TextAntiAliasingQuality = TextAntiAliasingQuality.High;
Series s = new Series("Series1");
c.Series.Clear();
c.Series.Add(s);
s.ChartType = SeriesChartType.Line;
s.Color = Color.Black;
ChartArea chartArea = new ChartArea("ChartArea1");
c.ChartAreas.Clear();
c.ChartAreas.Add(chartArea);
chartArea.BackColor = Color.FromArgb(255, 255, 255);
chartArea.BackSecondaryColor = Color.FromArgb(220, 220, 220);
chartArea.BackGradientStyle = GradientStyle.TopBottom;
chartArea.AxisX.LineColor = Color.Gray;
chartArea.AxisX.LineWidth = 2;
chartArea.AxisX.LineDashStyle = ChartDashStyle.Solid;
chartArea.AxisY.LineColor = Color.Gray;
chartArea.AxisY.LineWidth = 2;
chartArea.AxisY.LineDashStyle = ChartDashStyle.Solid;
chartArea.AxisX.MajorGrid.LineColor = Color.LightGray;
chartArea.AxisX.MajorGrid.LineDashStyle = ChartDashStyle.Dash;
chartArea.AxisY.MajorGrid.LineColor = Color.LightGray;
chartArea.AxisY.MajorGrid.LineDashStyle = ChartDashStyle.Dash;
c.BackColor = Color.Transparent;
chartArea.BackColor = Color.Transparent;
double[] x = new double[] { 1999, 2005 };
double[] y = new double[] { 3210, 13456 };
Axis ay = chartArea.AxisY;
ay.Maximum = 13456;
ay.Minimum = 3210;
Axis ax = chartArea.AxisX;
ax.Maximum = 2005;
ax.Minimum = 1999;
for (int i = 0; i < x.Length; i++)
{
double xvalue = x[i];
double yvalue = y[i];
s.Points.AddXY(xvalue, yvalue);
}
// Save chart-image to disk:
c.SaveImage("chartimage.png", ChartImageFormat.Png);
}
Set chart's AntiAliasing to AntiAliasingStyles.Graphics to disable the antialiasing on text.
Taken from this thread.
Maybe this help you
in your .aspx file where your chart code is, look for the asp:ChartArea tag. then add BackColor = "Transparent".
<asp:ChartArea Name="ChartArea1" BackColor="Transparent"
</asp:ChartArea>
Hope this help.
chart.TextAntiAliasingQuality = TextAntiAliasingQuality.SystemDefault;
I read this from here: http://forums.asp.net/p/1656335/4315304.aspx?Re%20Chart%20transparency%20and%20text%20quality

Resources