PyQt5 Pixmap from Built in Cursor - pyqt

I need to retrieve a cursor's pixmap in order to set a drag and drop action's default cursor.
drag = QtGui.QDrag(event.widget())
curs = QtGui.QCursor(QtCore.Qt.SizeHorCursor)
drag.setDragCursor(curs.pixmap()) # curs.pixmap() is returning a 0x0 pixmap
Calls like self.setCursor(curs) work just fine on widgets, properly displaying the cursor when I hover over them. However, like I said, PyQt seems to be messing up converting a valid cursor into a pixmap.
Is there a quick fix for this, or will I have to just use my own cursor images?

The API seems to be working exactly as documented:
QPixmap QCursor::pixmap() const
Returns the cursor pixmap. This is only valid if the cursor is a
pixmap cursor.
That is, it will only return a pixmap if you explicitly set one in the constructor (and the same goes for bitmaps).

Related

How to properly use XMaskEvent() function?

I am programming a GUI in plain C using X11 library, on Cygwin. When trying to read cursor movements over an open window using XMaskEvent() it works like a charm. It returns an XEvent structure whose coordinates point to the current mouse location and the event_type is a small positive integer number that corresponds to what happened (mouse move, button press, button release etc). So far so good. The problem is that this command blocks (it is supposed to) after each mouse move or button event so my program cannot do anything continuous.
So I tried to replace XMaskEvent() with XCheckMaskEvent() which should read an event, remove it from the queue and continue, so that my program can continue doing something. However, XCheckMaskEvent returns an event with zero coordinates, and constant crazy event_type of minus million-something. Whatever i do with the mouse or keyboard, I am always getting an empty event of a crazy type.
I am using the same event mask for both commands.
What am I doing wrong?

How to create a scalable multi-line button in Godot?

A Button in Godot can only hold a single line of text. I can overcome this limitation by placing RichTextLabel node inside the button.
Now the button can contain more lines of text, but its height doesn't change automatically when more lines are needed. Instead the text just overflows:
Of course I can manually resize the button to be higher, but I'd like this to happen automatically depending on the amount of text inside. Specifically, I'm generating a list of these buttons programmatically and showing inside a HBoxContainer, with some buttons having longer and other shorter text.
Is there a way to achieve this with Godot layout tools?
Since the Button is in a Container, it is in control of its rect_size. The best we can do is specify a rect_min_size. There is no layout preset to have a Control depend on children Control. So, to answer the question as posted: No, we cannot achieve this with Godot layout tools. We need some scripting.
We need to set the rect_min_size for the Button depending on the RichTextLabel. We can ask it for the height of its content with get_content_height. Which also means we need to set the width beforehand. However, it will not update right away when we set the text (we are going to use yield).
Apparently you don't want the Container to control the height of the Button. If that is the case, I think you can remove all the flags from size_flags_vertical.
About the width, since as I was explaining before we need to set the width to get the height… I suggest you let the Container expand the width of the Button as much a posible. Which mean setting both the Fill and Expand flags on size_flags_horizontal.
Then, with the RichTextLabel properly set to take as much width of the parent Button as possible, you can read it height, and use it to set the height of the rect_min_size of the Button.
One more thing: you want to set the mouse filter of the RichTextLabel to Ignore or Pass, or it will prevent pressing the Button.
This is the code I came up with:
var b := Button.new()
b.size_flags_vertical = 0
b.size_flags_horizontal = SIZE_EXPAND_FILL
add_child(b)
var l := RichTextLabel.new()
l.mouse_filter = Control.MOUSE_FILTER_IGNORE
l.set_anchors_and_margins_preset(Control.PRESET_WIDE)
l.text = "Some\nMultiline\nText"
b.add_child(l)
yield(get_tree(), "idle_frame")
b.rect_min_size.y = l.get_content_height()
I'd like this to happen automatically depending on the amount of text inside
Sadly changing the text does not resize, nor change the minimum size of the RichTextLabel. And RichTextLabel does not have a "text changed" signal. Nor "bbcode text changed" signal. Furthermore, it might not be feasible to intercept these properties (see append_bbcode et.al). It is proabaly easier to do with a regular Label.
Anyway, what I'm going to suggest for this is to make a Control that wraps the RichTextLabel, offers whatever interface you actually need, and in any method where you change the text, afterwards, you do the equivalent of this:
yield(get_tree(), "idle_frame")
b.rect_min_size.y = l.get_content_height()
(Godot 3.x)
Without using scripting, it is also possible to achieve the same goal by wrapping both nodes as sibilings within a container, for example a MarginContainer. Enable the RichTextLabel's fit_content_height property, which will result in the label expanding the container's area as much as necessary, which will in turn resize the Button.

how to draw a cursor in glfw while getting mouse input?

I have a program using glfw for window management and opengl for rendering. The program works on Windows and linux, and eventually Mac OSX so I want any solution to be portable.
glfw seems to either support a cursor, or getting full mouse input but not both. For example, with the cursor enabled (default) the glfwscroll_callback does nothing. If I disable the cursor, then scrolling the mouse is captured but then the user cannot see where the mouse pointer is. That's ok if I can draw the cursor myself when I want but I cannot find any function to drawcursor at a particular location.
How does the cursor work, ie what is the hardware basis for the cursor? Is there a sprite in hardware still? If it's all in software, I suppose we could draw a cursor at the current mouse location the last thing in render. But that's not convenient. For one thing if the scene hasn't changed, I shut down rendering completely to reduce power.
Is there any way to manually draw a cursor on top of the current screen so that we don't have to manage the buffers manually? Is my only option to change the logic and not render the scene if nothing has changed, but to manually draw a cursor on top of the current scene every frame?

TextArea without Scrollbars

I have a TextArea in my application that actually takes no interactions from the user.
Is there a way to either
Remove the scrollbar entirely and let me handle what happens when the scrollbar would appear?
Use a different object to display text to the screen? I need to be able to append text, but I don't need it to be highlight-able or take any user input.
According to your needs, you need to use label.
If you need TextArea, to remove scrollBars, you can do the next :
Use lookupAll(java.lang.String selector) method to find scrollBars, and
call scrollBar.setOpacity(0.0) for each found scrollBar.
2a. Don't call setVisible(false), as visible property (I believe) is used to TextArea to control scrollBar visibility.

I need to draw a line moving with the cursor, but I want to avoid redrawing the whole window every 100ms

I have a program which displays a ruler on the screen, and with Xlib it polls for the cursor position every 100ms and updates the display. The display consists of numbers/lines etc, in particular a line indicating the position of the cursor (which is why it updates).
The problem is that the old line needs to be erased and the content underneath restored, so I have to redraw the whole window to reflect a change in position. Doing this 10 times a second results in a very flickery program.
I could only redraw the ruler after I have confirmed that the cursor is in a position to change the indicator line (i.e. within the bounds of the ruler), but it would still flicker pretty bad when it was updating.
Sort of a noob to GTK and Xlib and all, any advice would be appreciated.
Code is at https://github.com/zjmichen/zRuler
Well you have arrived at one of the earliest problems faced when cursors were being implemented!! Cursor changes are so frequent that redrawing full window every time just doesn't make any sense! Coming to your problem, look at what is needed & what exactly you are doing. Do you need to update the full window when cursor moves? No. You need to update only a section of the window so don't update the whole window. Off the top, I can think of 2 ways of reducing flicker:
1. Simple way is to make use of GdkCursor. Create a new cursor from the pixmap (Sample provided on the developer page) with the shape of your need, a line in your case. Associate cursor with the GdkWindow of your application's main window. This way you don't have to track cursor & draw the line. The cursor itself will appear as the line (so you don't to bother about clearing & redrawing it). Now in the timer callback where you redraw the complete window, redraw only the component which has to be updated on cursor position change. This should hopefully reduce the flicker as you are not drawing all the components.
2. In case you don't want to use GdkCursor, you could create a separate transparent window on top of application window dedicated to cursor. In this approach you can update only the cursor window & the component in the application window which is to updated on change in cursor position. This way other components in the application window are not redrawn each time & this hopefully should also be able to reduce flicker.
Hope this helps!

Resources