How to draw connections between items in a QTreeView - c++

I wonder how to draw the lines connecting the items in a QTreeView as illustrated in the picture under Tree Model. My program will run on different platforms and thus use different styles. Can I guarantee that the items are drawn as desired?
I feel, using style sheets might be problematic because certain styles do not print such lines and using a delagate might lead me into issues of double drawing.

There's an example in the documentation here showing exactly what you want to achieve using style sheets.
Please note that when you use style sheets QStyleSheetStyle kicks in, irregardless from the QStyle your application is using at the moment. So if you decide to go this way you will override the look and feel of your control the same way, irregardless from the target platform.
If that is a problem, you may consider to use style sheets only for certain platforms. As an example:
#ifdef Q_OS_MAC
myControl->setStyleSheet(":/my_stylesheet_for_mac.qss");
#endif
Back to the example in the documentation, it uses a few images containing all the various lines (vertical, horizontal, branch, etc) and the ::branch subcontrol and its states to determine which image to use.
The result is something like this:
.
Obviously, you must change the code to show the vline picture instead of the arrows.
As a side node, I may suggest to consider why you want to do this if you are using native styles. If your application has a native look and feel, you should not alter it in any way. That is, if the target platform doesn't render lines to connect tree view items, then you shouldn't add those.
However, if your application is not required to look native across all the target platforms, you may consider using the same style (e.g. Fusion) and deliver the same user experience no matter what the platform is.

Related

wxPython GUI-wide settings

I have both a fundamental and technical wxpython question regarding GUI settings that are common to, and accessed by, many aspects of a single GUI.
In the interest of saving time I haven't cut/paste huge swathes of example code but I will explain it in words. I don't think I lose any clarity by doing so but shout if I do.
I have a wxpython GUI whose main feature is a notebook featuring many pages, the majority of which are data plots. Each page is defined according to unique class and while each class is different, they all access the same underlying data and are therefore fundamentally connected. Given this connection, there are some settings within the GUI that are common to all pages within the notebook. For example, the definition of the colour or shape of points on the various plots. Such settings may be used to define how the data is displayed e.g. car data may be red squares while bus data may be blue triangles.
Given that the plots on each notebook page are defined in separate classes, I could just repeat these definitions in each class. However, this feels like code duplication and since the colour/symbol definitions should be common across all plots, it feels like these definitions should be at the top GUI window level not at the notebook page level.
I have tried placing attributes within the top level window and I can access them from within a notebook page class using something along the lines of:
self.GetGrandParent(self).mySymbols
Where GetGrandParent is a crude way to work up the hierarchy of page /notebook / panel etc up to the main window. There may actually be more levels to traverse than just two.
My question is, is there a better way or more pythonic way to define GUI wide settings or attributes, once, at the top level (eg main frame) but access them from lower levels (eg notebook pages)?

Making a fancy looking window with messages stack

I try to make fancy looking messages viewer, where messages divided by formatting, other background of smth. similar. They need to looks like this - http://pastebin.com/GU1Lq087. What I found in wxWidgets to solve this problem, and why I can't use it:
wxHtmlWindow
Supports minimal HTML (a few tags). But big problem with this - html representation doesnt fill parent window. So element with width=100% will have 100% width only on standard window size. And even p tag doesnt have word wrapping (long long paragraph goes in one line with vertical scroolbar).
wxWebWiew
I need to have the ability to set generated HTML to it, but IE must to load some page first and I can rely only on IE background. It has some time to load page, even if I set HTML-string.
wxRichText
Most suitable for me. But I can't draw line like HTML's hr, or change background for the entire message block (to distinguish it from common background)
I need to show messages like this. But i didn't know how and which tool is better.
One way of achieving this would be using wxWebView with WebKit backend but I am afraid that Windows can only use IE's engine. However, there is project which allows you to use Gecko engine. I use WebKit for rendering chat in my application and it works really good (although I am using Qt). (http://www.kirix.com/labs/wxwebconnect.html)
You can always do it regular way - just create separate widget (I think it is called "frame" in wxWidgets) for single message. This way you get almost infinite possibilities. E.g. you can make "AbstractMessage" with virtual methods and then things like "AdministratorMessage", "MOTD" etc. will be a breeze.
wxRichText Most suitable for me. But I can't draw line like HTML's hr
Really? Have you looked at the docs?
( http://docs.wxwidgets.org/trunk/overview_richtextctrl.html )
Here's a couple simple ideas:
a. Write a line of blanks, underlined.
http://docs.wxwidgets.org/trunk/classwx_rich_text_ctrl.html#a333b2e675617ed2299cf91e7c0dbd0d8
b. Create an image of a horizontal line, display it using WriteImage
http://docs.wxwidgets.org/trunk/classwx_rich_text_ctrl.html#a1315611c0741d03e852ee26eba3a9d94
The funny thing is that what you want can be done using any of the 3 controls you mention. With wxHtmlWindow you just need to set its size correctly, with wxWebView I don't understand what your problem with it is at all and with wxRichTextCtrl you could just use separate controls for the areas with different backgrounds (you could almost certainly use a single control with different styles but using several controls seems simpler).

What Mac/iOS/Portable library can I use for formatting information to print onto label paper?

I'm looking for an open source (or cheap commercial) library that handles the difficulty of formatting information for standard label paper (say Avery 5160) for example. I would like to use the library in a Mac and iPhone app. I saw this similar question for a dedicated label printer, but I am looking for a Mac compatible library that will work with label paper loaded into any printer:
What options are available to developers for printing to a dedicated label printer?
Alternatively, I'm interested in suggestions about my best strategy for doing it myself... I'm not up for figuring out the intricacies of many different paper formats - I would probably target just one kind of US Letter label paper and one kind of A4 label paper. Which are the most popular?
Having written a (closed source) Mac codebase that actually does this, I can tell you that it's not the most difficult thing in the world. My codebase only supports Avery labels. I have a resource file in the app with geometry info for each kind of label (number of rows, columns, margin sizes, gutter sizes, etc.). I use this to layout a grids of properly sized subviews of the main print view, where each subview is one label. Each subview is responsible for modifying the layout of its information to fit its size. Conceivably this could be done using Cocoa Autolayout now (my code predates Autolayout).
You can download a CSV version of my label dimensions file here.
EDIT: I might also mention that you'll need to do some significant extra work for a solution that works on both Mac and iOS. The printing APIs are quite different between the two platforms. Even if you use a custom view to do printing on iOS, UIView and NSView aren't exactly the same. Still, with some careful planning, you should be able to come up with something that at least shares common core code on both platforms.

Java library to create and dynamically modify business diagrams

I am looking for a good java library to manipulate box, arrows and labels in order to dynamically create and fill diagrams like the following and render them to a png :
Another example
I can create a static template to be filled later, but I will need to dynamically create labels for every box and edges in the diagrams.
For now I have tried using batik to manipulate an svg template but creating multiline labels for the edges is proving quite complicated. The SVG way with batik seems to force me to create 1 text object for each label line with absolute positioning for each which is a real pain.
I would like to be able to define the label specifying only the text and the link they relate to, eventually some hints as to how it should be placed and let the library place them.
Any suggestions ?
If this is in a commercial scenario, the Java graph drawing library yFiles can be a good match for your requirements:
You can use a convenient API to create and style your diagram and automatically layout the diagram with lots and lots options to constrain the resulting layout to suit your needs.
Multi-line and (simple) HTML labels are supported out-of-the-box.
Also you can export to PNG (as well as other pixel based image formats) and vector graphics formats like SVG, PDF, EPS.
This can be done both in a regular Java (Swing) application as well as in a headless environment (e.g. to create images on a server and to send them to a web-based thin client dynamically).
To get a feel what can be done using that library, I suggest you take a look at the freely available graph editor application "yEd" that is based on yFiles and lets you try out the above steps in an interactive manner.
(Disclosure: I work for yWorks, but on Stackoverflow I do not represent my employer.)

Window like control in SketchFlow?

I've been playing around with SketchFlow from Microsoft and one thing that bothers me is that I cannot seem to find a window looking like sketch.
I would like it to have title bar and 3 "buttons" like all normal windows do (minimize, maximize, close buttons).
In Balsamiq Mockups this is very easy, however I don't see any kind of window-like sketches in SketchFlow.
I'm trying to mockup future desktop application.
You are correct that there isn't one built in. In SketchFlow you can easily make "component" screens that can be used multiple times. To create what you are looking for you could combine a sketch rectangle, with a couple of buttons and a textbox. You can select all of this content, right click it and make it into a component screen.
The MockupsLibrary also provides the mockups you are looking for. Once you've installed it, it'll appear in your assets as "ButtonWithIconMockup". You can select the "WindowMinimize", "WindowMaximize", and "WindowClose" for your IconImage attribute to get the desired result.
With Expression Blend 4, you can install the Mockup Controls by following the instructions at How to add mockup controls to your Expression Blend library. In the new Assets | Mockups category you will see a WindowMockup item that does exactly what you wanted.
To play around with the Mockup Controls, try the MockupDemonstration sample from the Help Welcome screen.
Unfortunately, there doesn't seem to be a builtin MenuStrip yet (although you can laboriously build one yourself from the non-sketchy SimpleMenu and SimpleMenuItem controls)? Also there doesn't seem to be any support for indicating keyboard accelerators (prefixing the desired letter with & doesn't work).
In general, it seems like Sketchflow really isn't designed to be used to prototype standard desktop applications?