I'm trying to create a mosaic plot series to include in a widget.
QStackedBarSeries seems like the best place to start but I'm unable to change the width of individual bars in it. (please correct me if there is a better/simpler starting point!)
I digged through the QBarSet to see if I can subclass it to scale it's width but it appears that the graphing is done in the QStackedBarSeries.
Is my only option to subclass QAbstractBarSeries to make the bar widths customizable?
Thanks!
I am moving an application of mine from an old GUI (where I used fixed sizes) to wxWidgets (where I am trying to learn the basis of sizers).
Inside the application I have several forms with quite complex structure. Nature of data and workflow suggest me to keep all these data together in a single screen.
But this screen has to be properly designed be usable.
Here's the old version of the form ...
... and here's more or less what I could come up with using sizers ...
Please note that I could not simply use a wxGridSizer, since some of the widgets span throughout the row, some other get out of the fixed grid etc.
Obviously I could keep working on it to make it less ugly, but I found myself thinking maybe sizers are not the correct tool to do it. To achieve what I want I would need something similar to wxGridSizer with some sort of colspan/rowspan mechanism, and maybe that wouldn't be enough.
So I started thinking to build a "Form Sizer" by myself that could go something like
int w,h;
GetClientSize(&w,&h);
MyFormSizer *formSizer(w,h);
formSizer->SetDimension( widget1, 100, 20 );
formSizer->SetDimension( widget2, 500, 20 );
formSizer->newRow();
formSizer->SetDimension( widget3, 100, 20 );
formSizer->SetDimension( widget4, 250, 20 );
formSizer->SetDimension( widget5, 250, 20 );
formSizer->Layout();
The user would set the relative sizes of every widget, to block the geometry of the form completely. To make this geometry fit the wxPanel when resizing Layout() would calculate an appropriate scaling factor f and then would set all sizes and positions doing something like
widget1->SetSize(CalculatedX, CalculatedY, 100/f, 20/f);
CalculatedX+=100/f;
widget2->SetSize(CalculatedX, CalculatedY, 500/f, 20/f);
CalculatedX+=0;
CalculatedY+=20/f;
and so on (this is just a scratch, take it as the rough idea; there should be mechanisms to avoid making everything too small to fit the text in the widgets and/or to scale the font size accordingly and such stuff).
Does it seem reasonable? How would you face the topic? This choice is going to affect quite a bit of my future developing, so any answer, criticism and comment will be very welcome
wxGridSizer might not fulfil your needs but more flexible classes such as wxGridBagSizer should do what you want. This class allows you to set items to span multiple rows and columns by setting wxGBSpan when calling wxGridBagSizer::Add.
As mentioned in #sjdowling's answer, you could use wxGridBagSizer. However I don't recommend using this class as it suffers from some problems of the absolute positioning, notably it makes it very difficult to move elements around it or to add them except at the very end.
It's true that wxWidgets sizers lack the ability to align elements across different sizes, which is what you'd need here if you used normal box or grid sizers and this is annoying. However you can work around it by fixing the sizes of the columns explicitly, either by just hard-coding them (please at least use dialog units and not pixels though to avoid broken layouts, especially in high DPI situations), or by iterating over all the labels and calling GetTextExtent() on all of them and choosing the longest one (this is much more reliable, especially when using translations which can drastically change the width of the string in pixels). Then simply assign this width to the labels you create: as the initial width is also the minimal width, this will ensure that all of them have this width and so are aligned, even if they are in different sizers.
As I wrote, this is somewhat annoying but really not that bad if you're creating the layout in the code. If you do it in a GUI designer, it's even uglier, but you can still call wxSizer::SetItemMinSize() from the code. Of course, the only real solution would be to add support for inter-sizer alignment, but for now this is still preferable to using wxGridBagSizer IMO.
This is a follow-up question of Making an editable flowchart in Qt/C++.
I want to add a QGraphicsItem to a QGraphicsGridLayout in a way that the item takes up its own spot in the grid and then automatically centers in its 'cell'.
I am using QGraphicsView and QGraphicsScene, and drag-and-drop to any location works, but it's looking messy, and could prove to be problematic in future development.
What do I have to do so the item snaps to the grid and centers in its cell?
PS: I have taken a look at http://qt-project.org/doc/qt-4.8/graphicsview-basicgraphicslayouts.html as an example but this didn't help me to solve my problem.
Also, it'd be ideal to have this layout and its data be savable to a text file, etc. I'm assuming a 2D array would be the best way to do this. Should I somehow make the QGraphicsGridLayout based on that array, or is there a better solution?
I have a styled QScrollBar on my table which uses an image for the handle of the scroll bar. The handle is rounded at the edges (with transparency in the image around the edges, of course). Now the problem is that i can't seem to make it re-size nicely.
It's a vertical scroll-bar, so the only way I found to work so far is to set:
background-image: url(:/res/img/scrollbar-vhandle.png);
background-repeat: repeat-y;
in my stylesheet. Which does what it's supposed to, only my scroll bar looks ugly, especially because of the rounded corners.
The image could be 'stretched' nicely by repeating a 1px high line from it's y-center. But even y-stretching should be ok. I just can't find a good way to do it.
Something like a QPushButton, where 9 images can be used for 1 button in order to scale would work, but unfortunately doesn't seem like it does.
So, if anyone can let me know if it's a way to do it through stylesheets (or deriving from QScrollBar, and repainting the handle) i'd appreciate it very much.
If you need more info, please let me know.
Well, as you say, you could inherit from the scrollbar and overload the paintEvent function. Therein you can pretty much to whatever you want, for example compute your new pixmap by repeating that one line and painting it. There are actually a couple of functions in QPixmap that should make this relatively easy.
I subclassed QGraphicsItem and reimplemented paint.
In paint I wrote something like this for labeling the item:
painter->drawText("Test",10,40);
After some time I think It may be useful to handle labeling with seperate item. So I wrote something like this.
QGraphicsTextItem *label = new QGraphicsTextItem("TEST",this);
setPos(10,40);
But two "TEST" drawing do not appear in the same place on screen. I guess difference may be related with item coordinates - scene coordinates. I tried all mapFrom... and mapTo... combinations inside QGraphicsItem interface but no progress. I want to drawings to appear in the same place on screen.
What I miss?
I assume that you are using the same font size and type in both cases. If the difference in position is very small the reason can be the QGraphicTextItem is using some padding for the text it contains. I would try to use QGraphicsSimpleTextItem that is not going to add fancy stuff internally and see if you still have the same problem. The coordinates system is the same one if you use painter or setPost so that is not the problem. If this doesn't help I will suggest to specify the same rect for both to avoid Qt adding it owns separation spaces.