Qt Action Dropdown Widget - user-interface

I am creating a drawing application where the user can insert primitive shapes, like circles, triangles, etc. In the toolbar, I would like to have a single "Add Shape" button that shows a dropdown widget when pressed. In the dropdown, I would like to have a grid of QAction icons representing the different shapes the user can add. This is almost identical to how one adds basic shapes in powerpoint.
I know how to create a dropdown menu using a QToolButton and setMenu. However, this lists actions in a traditional menu format. I want the QActions showing only their icons, and to have them arranged in a grid - like a toolbar that has multiple rows. Do I have to create a custom widget for this?
Thanks!

By default QMenu uses a vertical layout to display the QActions so If you want a grid you need to subclass it to create your custom one.

Related

How to display elements inside NSCollectionView with various shapes

I am a rookie Cocoa guy. I need to design and implement a view which will show collection of labels on Mac OS using Xamarin. These labels will have a text and color associated with them. When shown inside the view, label should expand till it covers whole text and it will be shown with background and foreground colors.
I have attached the picture of this user control on Windows, you can see that labels inside the StackPanel are expanding till they cover the whole text. Hope this gives better idea about my ask.
The $64,000 question is "are these labels controls?" In other words, do you expect the user to click on these to do something, or are they just for display?
If your answer is "just for display", the solution is super simple: Use an NSTextField and programmatically add attributed text (NSAttributedString) to it. Attributed text attaches display properties to runs of text within the field; properties like "background color".
If you want these to be buttons that you can click on, then things get a lot more complicated.
Since you apparently want the button layout to "flow", you might look into imbedding buttons (well, button cells) into an NSTextField using attachments. This is normally how non-text content (say, an image) can be inserted, but with some fiddling it can actually be anything a control cell can draw. See How to insert a NSButton into a NSTextView? (inline).
Warning: this is not a "rookie" topic and will involve control cells and custom event handling.
If I were doing this, I'd probably just create NSButton objects for each label (choosing an appropriate style/look like NSRecessedBezelStyle), create a custom subclass of NSView to contain them, and then override the layout method to position all of the buttons the way I want.
To be thorough, I'd also override the intrinsic size methods so the whole thing could participate in auto-layout, based on the number and size of buttons it contained.

How to create consistent toolbar buttons with icons

Desired look
I wish to make a toolbar for my app that will contain some simple buttons, each with a single monochromatic icon. Here is an example of some toolbar buttons similar to I'm trying to achieve, from Mail's compose window:
Notice these buttons have a consistent size, inner padding, padding, and shading. This is a pretty consistent style across macOS, present in Mail, Safari, Finder, etc. This leads me to suspect there's a standardized UI component for creating such buttons.
If I use a segmented control, each button looks correct, with each icon being correctly padded:
Now I would like to add individual buttons that match the style.
Attempt 1
My first attempt was to add a "Push Button" (NSButton) to the toolbar:
This resulted in a wide button that's a bit too short, and not lined up with the segmented control:
Attempt 2
My second attempt was to use a segmented control, with only 1 segment.
This resulted in a button that's the right shape, size, etc., but it was off center relative to its label.
Naturally, I can manually adjust the button to match the goal, but I feel like I'm missing something. What's the proper way to create these standard buttons?
This is actually quite easy to do and you were close already.
You can use NSButton for that. Note that it has different styles (defined in NSButton.BezelStyle) to choose from. The default one is the one to use inside windows and modals. But for toolbars, to match the style of segmented controls and search bars, you can choose the style .texturedRounded.
You can also set the style via Interface Builder. Note that you have to select the button itself, not the toolbar item around it.
To get the correct size, you seem to set the icon within the toolbar item, not the button itself.
Here is my result:

How to create a dropdown in Xamarin.Forms that displayes different content per item?

How am i going to create a dropdown that displays different content depending on the selected item? For example, there are 3 items on a dropdown namely Chart1, Chart2 and Chart3. When i choose Chart1 it should display a Pie Chart. When i choose Chart2 it should display a Bar Grap. When i choose Chart3 it should display a Line Graph. Is that even possible to do? Thank you.
I assume you already have a way to create your charts?
If not there are plenty of 3rd party options out there for charting.
To have the three separate views in the one page as you are trying to do
all you would need to do is create three separate ContentView with your three different charts. Use a RelativeLayout or an AbsoluteLayout to lay the three ContentView over the top of each other.
I'll assume you are using a Picker control as your drop down.
if so then just use the picker.SelectedIndexChanged event to change the visibility of each of the chart ContentView according to which option was selected

In WinRT we have ListView and GridView - how about a simple list with columns and details (like Explorer details view)

I just want to create a list with data and columns (sortable). I don't want tiles, I don't want right scrolling. I just want a list like the "Listview" Win32 common control. Or am I forced into the tile metaphor.
I believe they are not at a metaphor but from my point ListView in Win32 is one.
ListView in Win32 is a very limited control, unflexible and too ugly.
ListView and GridView xaml controls are far better aproach, I know.. switch from old style controls to new style is easy if you come from scratch but if you have old style background... is hard... I know.
If your lvw32 grows vertically based on data use a Listview (xaml) in wich each item is a Row and use the item template to put in a gridview,the gridview will be one register with all attributes (columns).
So your ListView will have a collection of Rows, each Row is a GridView who is a Collection of attributes.
This is a way, but you have a lot of different options.

Any layout/geometry management for Cocoa?

If i create WinForms / Qt / Gtk application i use so called "layout managers" (or "geometry managers") to automatically layout my UI according to text inside widgets and my instructions. For example, if i layout a window with big edit field and 2 buttons below it aligned right i write following code "Create a window with vertical layout manager. Add edit widget as first item and horizontal layout manager as second item. For horizontal layout manager add spacer as first item, button as second and button as third". My window will be automatically resized according to button labels and edit field size. Also, if i resize my window all items will be resized automatically.
Is it something like layout managers for OSX? I have found that NSView can be added into hierarchy, but i can't find any ways to instruct parent NSView something like "arrange child NSViews vertically".
You should read about Cocoa Auto Layout, new in OS X 10.7.

Resources