I'm having the following issue with GTK2:
I created two buttons with labels inside an horizontal box. (I intend to pile several hboxes)
However there's an issue: When I make the box_pack functions they go like this:
gtk_box_pack_start(GTK_BOX(hbox1), button1, FALSE, FALSE, 0);
gtk_box_pack_start(GTK_BOX(hbox1), button2, FALSE, FALSE, 0);
Despite putting them both false, the buttons still expand vertically, making the "hbox1" ocupy all the space that is left on the parent box. I want the buttons to expand only to the minimum height required for the label to be displayed properly (like it usually happens on vertical boxes).
I heard that in GTK3 you could use the gtk_widget_set_vexpand and gtk_widget_set_hexpand functions. However, these do not seem to exist in GTK2, as they are on recognized....
Any solution for this?
(Not just this case with horizontal boxes, but with the respective case in vertical boxes)
This is an older question, but an important one. In short, set the valign property of the problematic widget to Gtk.Align.CENTER, just as #user7537486's comment on the original question said. Hope that solves it!
If I understood correctly, you need another hbox to behave like a expander, more or less like this:
|button|spander|
so, when you expand:
|button| spander|
button still at its minimum size....
is that what you asking for?
Related
I'm trying to write an interface in GTK+2, and I can't find a way to make sure toggle buttons and progress bars won't try to fill up entire space avaiable to them.
My interface has a picture, and a bunch of progress bars and toggle buttons on the other side. If there's enough of them to make the entire vbox with them higher than the picture itself, everything is fine:
However, when there isn't enough of them, they get vertically stretched, which makes them look wrong:
I can't find any way to make sure this doesn't happen, the only thing that I found in the documentation related to setting height of these widgets is setting their minimal height. I'm looking for a way to ensure these widgets don't try to take up all space they can.
My code is here. I couldn't include the placeholder image that I'm using here, but it's just a 128x128 placeholder that can be easily replaced if needed.
When you create your widget for a single CPU, you add it to the parent container:
gtk_container_add(GTK_CONTAINER (vbox), current->box);
Container functions are generic for multiple types of widgets to hold children but don't allow specific adjustments.
In a box you can specify whether the available space should be added to the child widget and how it should appear.
To use this you need to change this line to:
gtk_box_pack_start(GTK_BOX(vbox), current->box, FALSE, FALSE, <borderline>);
This should prevent the widget to be enlarged.
The Visual Studio WinForms designer lets you snap together text boxes, list boxes, buttons, and so forth reasonably well. However, a check box with CheckAlign=MiddleRight does not work quite like the others, because it has two components: the built-in label, and the check box itself. If you line up the text with other labels, the check box is left floating and will not automatically line up. You can turn off AutoSize and attempt to size the CheckBox control so the check box lines up, but this is touchy and will be thrown off by custom font sizes.
In this example, I've almost lined up the check box with the other controls, but not quite:
If I had several check boxes it would be a real headache, as with AutoSize turned off the position of the check box is relative to the end of the text, so each control has to be individually sized pixel by pixel.
What's the best way to line up check boxes with other controls?
One workaround is to not include text with the CheckBox and instead have a separate Label control. However, by doing so you lose the ability to click on the label to toggle the check box. On a high-resolution screen, clicking a 10x10 pixel is finicky, a poor UX experience. You could add an OnClick event to the label, of course, but that seems like solving the wrong problem.
Here's an example of someone else with the same issue: in the preferences panel in Oracle SQL Developer, when there's a mix of properties the check boxes are handled with separate labels and boxes:
Personally, i avoid that issue by not having the CheckBoxes aligned to the right:
rather than having the caption on the left.
I have a program which shows two GtkTreeViews packed inside a GtkPaned (sscce: here):
gtk_paned_add1(GTK_PANED(paned), tree_view1);
gtk_paned_add2(GTK_PANED(paned), tree_view2);
The result is the following:
However, the tables can become bigger, so I added then to GtkScrolledWindows (sscce: here):
GtkWidget *scrolled_window1 = gtk_scrolled_window_new(NULL, NULL),
*scrolled_window2 = gtk_scrolled_window_new(NULL, NULL);
gtk_container_add(GTK_CONTAINER(scrolled_window1), tree_view1);
gtk_container_add(GTK_CONTAINER(scrolled_window2), tree_view2);
gtk_paned_add1(GTK_PANED(paned), scrolled_window1);
gtk_paned_add2(GTK_PANED(paned), scrolled_window2);
However, now the window collapses itself to the point it is almost a thin trance, as in the screenshot below:
If I maximize the window, the first column does not appear (although I can manually expand it):
So, what is the best method of getting the appearance of the first screenshot wen using GtkScrolledWindows in this scenario? Also, could I define the size of the pane columns in relation to one another (for example, 30% for the first one, 70% for the second one?
I've been using this pattern (I'd be happy if someone posted a better answer):
GtkWidget* treeView_, pane1_;
// [Removed code to create and show the widget heirarchy.]
GtkRequisition sizeReq;
gtk_widget_size_request(treeView_, &sizeReq); // get tree's preferred size
gtk_paned_set_position(GTK_PANED(pane1_), sizeReq.width);
This gets pretty close, but you'll probably have a horizontal scrollbar with a few hidden pixels. Since our application remembers the user's adjustments to the pane positions, it only needs to look "good enough" on initial layout.
Also, there are requirements for gtk_widget_size_request() returning something meaningful. In my case, I've invoked a gtk_widget_show_all() on the hierarchy before retrieving the size request.
The solution I adopted was to actually set the size of the scrolled windows (sscce):
gtk_widget_set_size_request(scrolled_window1, 200, 600);
gtk_widget_set_size_request(scrolled_window2, 600, 600);
The result was, as one would expect, a window with 800x600:
I am not satisfied: this approach relies on arbitrary sizes and it seems too "manual". Nonetheless, I want to use my software so I will adopt it for now.
I work on gschem, a free software tool for editing electronics schematic diagrams. Recently we have encountered a problem using a GtkScrolledWindow containing a GtkTextView.
Context
Recent versions of Ubuntu use overlay scrollbars, which mean that GtkScrolledWindows no longer set a minimum height that provides enough room for a legacy scrollbar (in fact, they have a minimum height of 0). Likewise, a GtkTextView with no text to display requests a height of 0. This means that one of the scrollable GtkTextViews in gschem has been being displayed as one pixel in height, and this is obviously unusable.
In the dialog box on the right of the screenshot shown above, note the invisible widget between the "Value:" label and the "Add" button.
This has been reported independently by several users -- see also the bug report.
Question
Obviously, we could fix this by doing:
g_object_set (textview, "height-request", 100, NULL);
However, this is pretty inelegant, and will break for users who set very large font sizes in pixels (e.g. users with vision problems or who use high-DPI screens).
Ideally, therefore, we want to set the minimum size of the GtkTextView relative to the default font size, e.g. tell it to "show at least three lines of text".
Can anyone suggest a sensible/elegant approach for doing this?
Just disable the ubuntu overlay scrollbars in your application by doing:
putenv("LIBOVERLAY_SCROLLBAR=0");
Not ideal, but it's a quite good until you can find a more permanent solution. Alternatively just wait until Ubuntu disables overlay scrollbars...
I would add code to dig out the current/default style information, use that to figure out the font baseline height, and then compute some rough size allocation based on that, around three lines as you mention.
Does it have to be a textview ? If you can use an eventbox instead, then you can make a cairo surface from it, render the text with pango, and then use pango_layout_get_size() to get the text height.
Likewise, a GtkTextView with no text to display requests a height of 0.
Probably you can create GtkTextView with some text inside. Like several spaces, and set empty value after creation.
I want to implement scrolling functionality in winforms. I need text to scroll like a marquee, but from the bottom to the top.
How can I do that?
The question is a bit vague, but I think what you want to do is set AutoScroll=true on your form and scrolling will be automatically provided.
I think I know what you want to do. (making a specific area scrollable)
You can do it this way:
Create a form
Drag a panel onto it.
Set the panel docking...the way you want it
Set AutoScroll = true for the panel(Eric has suggested this).
Now drag any other control onto the
the panel.
The panel area is now scrollable.
If you want to make the whole form scrollable then set AutoScroll = true for the form.
In relation to your comment to PK's answer, you'd need to simply code into a timer, or other method, to change the labels/controls Y (Or Top) value, decrementing it as required. Once it reaches -(control Height), change to (Form.Height)+(Control Height) and continue decrementing.