i3blocks | The hacker-friendly status_command for Sway and i3 | Code Editor library
kandi X-RAY | i3blocks Summary
kandi X-RAY | i3blocks Summary
The hacker-friendly status_command for Sway and i3
Support
Quality
Security
License
Reuse
Top functions reviewed by kandi - BETA
Currently covering the most popular Java, JavaScript and Python libraries. See a Sample of i3blocks
i3blocks Key Features
i3blocks Examples and Code Snippets
Community Discussions
Trending Discussions on i3blocks
QUESTION
I am working on making dropdown/popup windows for my i3bar/i3blocks setup. The idea is to have a Qt.Popup type window open when a certain i3block is clicked, which will be positioned above the i3block to look like a popup menu. I have most of this working, but would like to add partial borders to the Qt window like I have drawn on in the picture (in red):
Ideally the border would not go all the way around the pop up but would stop where the popup "connects" to the i3block it extends, (the battery i3block in the example). The border should however extend on the bottom to separate the popup from other i3blocks (example: the calendar block). This is not the only popup that I would like to make and others might "hang over" neighboring i3blocks more or less and possibly on both sides. The start and end location of the border brake (x and y, if needed) would be in px.
I have looked at using QGraphicsView to simply draw those lines on, but can't figure out how to get any QGraphics to work when the window is a QDialog. Is adding the graphics possible? If so, how?
Note: I don't want to use a background image, because I want the border line width to be the same regardless of the window size.
Here is the relevant code:
...ANSWER
Answered 2021-Aug-23 at 21:26QGraphicsView is intended to show 2D custom graphics itemd in a scene, not to customize the painting of widgets. In order to achieve what you want, you need to use a QPainter created within the paintEvent
of the widget, which is the function that is called by any widget whenever they need to be displayed.
There are various functions that draw primitive graphics, like rectangles, ellipses and text; in your case you need to work with lines (since you're not drawing a full rectangle) but, since lines drawn individually are not connected, the result might not be fine if the border has a width bigger than one pixel, so you should opt for drawPolyline
.
The approach is the following:
- get the current widget rectangle, and subtract one pixel from the right and the bottom to get the actual painting rectangle;
- reduce the rectangle by half the width of the border that is being drawn (lines extend from their middle by half of the pen size: a horizontal line drawn at
y = 10
with a width by 2 is drawn fromy = 9
toy = 11
); - get the point at the right of the bottom edge, where the small line has to "stop";
- set the pen of the border (color and width);
- draw the polyline;
Community Discussions, Code Snippets contain sources that include Stack Exchange Network
Vulnerabilities
No vulnerabilities reported
Install i3blocks
Support
Reuse Trending Solutions
Find, review, and download reusable Libraries, Code Snippets, Cloud APIs from over 650 million Knowledge Items
Find more librariesStay Updated
Subscribe to our newsletter for trending solutions and developer bootcamps
Share this Page