Is there a way in Gtk+ to stack one widget on top of another -- not counting GtkFixed? GtkFixed doesn't work well for two reasons: 1) I need Z order, and 2) I need one widget to stretch and fill provided space.
I had this exact issue using a Gtk::Fixed (actually gtk.Fixed -- pygtk -- but I think it's all the same underneath) and I was able to handle it quite easily by manipulating each widget's window.
In my case, the widgets already are EventBox instances, and I just needed to make sure that the one I was dragging around was on top, because otherwise it slid underneath others, which looked quite wrong. The solution was as simple as calling "widget.window.raise_()" to raise the widget's underlying window when the widget was clicked to begin the drag.
So I'm basically just reaffirming that the previous answer works, but I wanted to point out that it's actually pretty easy. It sounds like you may need to create some EventBoxes to hold your widgets, but after that it should just work.
You can see the code I was working on at http://github.com/divegeek/BlockHead
I don't think there is a proper container in standard GTK. I would subclass Gtk::Fixed... it is still the closest one you can get, and if you use gtkmm then subclassing shouldn't be very difficult¹. Then you can control the dimensions of all widgets, stretching one selected child to fill space.
To control Z-axis you will probably need to manipulate widget's X windows--check GDK documentation on topic of GDK windows². I remember that in PyGTK each widget has gtk.Widget.window property, I guess that the same is for gtkmm. This assumes that all your child widgets have X windows, so f.e. you'll need to wrap Gtk::Label inside Gtk::EventBox.
¹ http://www.gtkmm.org/docs/gtkmm-2.4/docs/tutorial/html/chapter-customwidgets.html
² http://www.gtkmm.org/docs/gtkmm-2.4/docs/reference/html/classGdk_1_1Window.html#6eef65b862344ad01b01e527f2c39741
I was able to do exactly that -
display one widget filling the entire space, and then another on top at a fixed location, both visible at the same time
in gtk2 by using GtkFixed, working out a suitable insertion order (first inserted - bottom, last inserted - top), and - most importantly!! - forcing GtkFixed to have it's own window:
`f := gtk_fixed_new();
gtk_widget_set_has_window(f, 1);`
If you don't do set_has_window(f, 1), all children windows will be inserted into some parent widget/window (see gtk_fixed_realize() in gtkfixed.c), and that might create z-order mess.
Related
For mouse I'm using:
ourEvent = CGEventCreate(None);
currentpos = CGEventGetLocation(ourEvent);
What can I use for the caret?
First the bad news.
Not every app is Cocoa-based, and those that are neither Cocoa nor Carbon nor a straight mix of the two—i.e., those based on wxWidgets, Qt, or some other cross-platform framework—typically reimplement the entire GUI stack on top of raw event and drawing primitives.
That means that there is typically no way to get this information from those applications (unless they're scriptable and expose it that way).
The good news is, Cocoa apps and some Carbon apps may expose this via Accessibility.
The user will need to have assistive devices turned on in System Preferences. Once that condition is met, you can use the Accessibility framework to get the frontmost application, get its focused window, get its focused view, and get its selection ranges.
A text view with an insertion point has exactly one selection range, and that range is empty (length=0). The location is where the insertion point is.
Of course, those are character indexes, not on-screen bounds.
That's where parameterized attributes come in. There's one for converting ranges to bounds. That's the one you want.
Theoretically (I haven't tried this), you should be able to convert the empty range of the insertion point to an empty or nearly-empty rectangle whose location is somewhere within the vertical line of the insertion point.
Make sure you test this with text views that are in scroll views, particularly when the insertion point is scrolled partially or completely out of view.
You'll want to use the Accessibility Inspector to see for yourself where your application will need to look, and to test individual applications and investigate reported failures.
You can get it from the Developer Downloads page, in the “Accessibility Tools” disk image.
If you want to focus a window, forging a mouse event to click on it is a bad idea—anything can happen if you click on the wrong thing. Send the window an kAXRaiseAction action instead.
If you want to set a text view's insertion point (and are looking to find where you need to forge a mouse event to click to set it in the desired position), again, that's a bad way to do it. Set the view's kAXSelectedTextRangesAttribute attribute instead. Again, an insertion point is a single empty range.
Did you try like this below?
NSPoint p=[[NSApp currentEvent]locationInWindow];
CGFloat X=p.x;
CGFloat Y=p.y;
NSLog(#"%f %f",X,Y);
I need to implement a threaded view of sorts in an old VB6 app. It should look similar to this:
So, it's like a TreeView of sorts but there are buttons on the right (for each row) that could be pressed. The view does not need to collapse - it always stays in the expanded mode. The users should be able to respond to each node (via the comment button on the far right). And, of course, users should be able to scroll through the entries.
What are some of the ways I could implement this? I am open to 3rd party controls, paid or not.
VSFlexGrid has an outline mode. You can set the indent per row via the RowOutlineLevel property. It supports word wrap, images, etc within its cells/columns so you should be able to get pretty close to what you want. It also supports owner-drawn which lets you fully customize the cell painting (for example, to get those rounded corners).
I'm sure there are other controls out there as well...
I have two NSWindows, one of which is the child of the other. Basically what I want to accomplish is for the child to pop out and appear to extend the parent. If you like, think of it as opening a book: the cover flips out and ends up at the same Z order as the title page.
However I have the problem that one of the windows is always casting a shadow on the other. Is there any way to have them be on the same Z, so that neither casts a shadow on the other, but both cast shadows on windows below them?
Could this work? Take your existing child window, and remove the shadow with a setShadow:false call. Meanwhile create a third dummy window Z-ordered behind the two existing windows. Make it so that this window is always the same size and shape as the true child window and leave the shadow on.
Two possible problems with this: (1) a weird 'double shadow' at the point(s) where the two shadows intersect. (2) The shadow that the window with the focus casts is much larger than the shadow that windows without the focus cast. So if focus shifts between your two windows, the shadow might change size. Not sure how you'd get around that problem.
Otherwise your only choice may be to put both your windows with shadows turned off in a yucky container window which casts the one shadow. This would be a pretty radical UI change, but in my experience apps that tinker with the default appearance of their application's 'outer edge' or try to code their own partial transparency without using OS features rarely run smoothly.
I'm writing a diagram editor in Qt with Graphics View Framework.
Currently I'm just trying to create a simple Node (QGraphicsItem) on GraphScene (QGraphicsScene). I created a Canvas (QGraphicsView) and added a grid to it. I can even add Nodes and move them around on scene. My final goal is to have different working modes, editing and styling options, etc. For now I just want to know how can I setup selection for Nodes already present on scene. I tried doing it with mouse events but noticed that event calls for selection and Node insertion overlap... When I try to select something a new Node is created... This is my first Qt application so I don't fully understand how the functionality I want to achieve should be designed.
How the Selection Rectangle should be properly drawn?
How should I manage mouse events that conflict with each other?
You can use a checkable button/action(that's a QPushButton/QAction with a checkable property set to 'true) to switch between Edit & Insert mode. Then you check the state in your mouse event and insert a new item only if you're in Insertion mode.
You can also distinct between mouse buttons - insert item when dragged with the right button for example
Or use QKeyboardModifiers - for example: on drag + Ctrl - insert item.
Hope this helps.
In case of the overlapping mouse events, you should have a single place (like QGraphicsView to handle the mouse clicking/moving events) and create a state machine and then handle the events according to the state you are in. You need to plan your architecture well and that can be really complex task.
set your state enum/constants
refer to the current machine state in your events in your if conditions
keep your "business logic" on a single place
Like it's shown in these two NodeEditor tutorials #11 and #12: https://www.youtube.com/watch?v=pk4v2xuXlm4 and https://www.youtube.com/watch?v=-VYcQojkloE)
If you still want more in depth explanation of the functionality and events of Qt, here is a full list of tutorials with implementing all possible features like dragging edges to nodes, selecting them and deleting them, cutting edges, serialization, etc., you can have a look on the whole list of 50 tutorials I've recorded here: https://www.blenderfreak.com/tutorials/node-editor-tutorial-series/.
I'm putting a link to the whole list, since it's not possible to write all the code on this page...
I'm trying to work out what the best way to draw over the top of all other items on the screen on OS X. I don't want to impede the user's ability to interact with their applications, but want to 'annotate' them. I want to be able to draw up to 20 different annotations. The top half of this screenshot from Gizmodo happens to nicely show the kind of thing I want to do. http://gizmodo.com/assets/resources/2006/07/04%20Safari.jpg (sorry, I'm too new to post it as an image)
The questions I think I need to answer are:
Should I create a single window for
each drawing and draw to that? If
so, how do I minimise overhead?
What kind of window or other context should I use given that I don't want any window
decoration?
I don't think I want the overhead of creating 20 windows, but I also don't know that I want to create a full-screen, invisible window that contains my context (I presume a subclassed NSView), because I fear that will a) cause problems interacting with what's below and b) break the niceties of only redrawing when necessary (my actual drawing will likely only cover 10% of the screen)
I've not worked with Quartz2d before, so I just can't get my head around how to get the 'right' context to draw on from the documentation. Any help would be appreciated.
Thanks,
Who
You can only draw into a window. You can make a transparent, borderless window but it will need to be at the front.
You could set it's level to something like NSPopUpMenuWindowLevel to make it draw above other windows (this will be very annoying to users) but clicking on it will:
a) activate and bring to the front your app
b) Prevent the app underneath receiving mouse events
Is that what you want?