How can I get a hidden QGraphicsItem in a QGraphicsLayout to give up its space? - qt

I have a QGraphicsLinearLayout with a series of QGraphicsWidgets within. I can hide the widgets just fine, but the layout spaces out all of the remaining widgets as if the hidden ones are still visible. How can I get the layout to use this space?
My code is something like this:
//scene is a QGraphicsScene*, myWidget# inherits QGraphicsWidget
scene->addItem(myWidget1);
layout->addItem(myWidget1);
scene->addItem(myWidget2);
layout->addItem(myWidget2)
scene->addItem(myWidget3);
layout->addItem(myWidget3)
//then later, I call
myWidget2->hide();
But although myWidget2 is now invisible, the layout is still spaced as though it were there. How can I change that?
Thanks.

Try calling QGraphicsLinearLayout::invalidate() to clear any cached geometry information after hiding the widget. If that doesn't help I would assume that removing the widget from the layout (if that is feasible for you) should do it.

I think you are loking for QWidget::findChild<T>(Qstring name)
name - an object name which can be set with QObject::setObjectName(Qstring name)
T - is a type of an object you are loking for.
so in your case code should look like:
MyWidget* myWidget1 = new MyWidget(this);
myWidget1->setObjectName("myWidget1");
........
MyWidget* requiredWidget=scene->findChild<MyWidget*>("myWidget1");

Related

Controlsfx Properties order of items

I've a linkedhashmap that I put into Properties file, and it shows the fields in the menu. I've an others color option and I want it to be seen at the end.
So colormap is my linkedhashmap and I put others the end. So when I look inside colormap, last element is Others. But changes when I put it in properties file.
My code is like this:
colormap.put("Others",Color.GRAY);
Properties prop = new Properties();
prop.putAll(colormap);
And order changes inside prop. Do you have any idea how to solve this problem?
The java.util.Properties type inherits from java.util.Hashtable and there is no guarantee that the table will retain its order even after you've loaded the properties.
to fix that you can use OrderedProperties

Minecraft Modding: Make entity teleport up when hit by a certain item

I am learning to create minecraft mods.
I would like to know how to make an entity teleport upwards when hit by a certain item. I have already made the item.
Override either Item#onLeftClickEntity(ItemStack, EntityPlayer, Entity) or Item#hitEntity(ItemStack, EntityLivingBase, EntityLivingBase). In that method set the target's Y position to whatever you want.
I think you might be able to use onLeftClickEntity. in the item class for your item, make a
onLeftClickEntity method. inside that method, it should be as simple as using motionY. untested though, and for 1.12.2.

windows form make a form starts at a specific position

I made a simple program with two forms. the first form is small, the second one is large.
I already handled the screen resolution thing so the scroll is working and I tested the application on many screen sizes and resolutions.
my problem is this:
when I go from the first form to the second form, the second form doesn't start from the top left of the screen so the result is this:
I have to drag it to the top to see the two buttons at the bottom like this:
my question is: is there a way to make this form starts as in the second image, not the first one?
There is a proprety called StartPosition with it you can define the startup position of a form
PS : if you want a costum position for exemple if you wan it to be in the coordinate : X=15 and Y =20
in the FormLoad Event (double click the form ;) ) put this :
Form1.Location = new Point(15, 20);
OR THIS :
Form1.Top=20;
Form1.Left=15;
Forms.StartPosition is the property to work with.
Usually setting it to CenterParent or CenterScreen should work well for your requirement.
Instead if you want to fine tune the position of the form then you should set the property to Manual and then work with the Location property (a Point structure) calculating the correct location desidered.
Also, keep in mind that if you want to manually work with Location and Size of the form you should do it overriding the OnLoad event, as explained in this question

Set a new layout on button

I have a layout (containing QLabels and QSpacers) set on a button and I want to replace this with a new one. To do this I have made the following code:
while(!layout.isEmpty())
{
delete(layout.takeAt(0));
}
After this I set the new layout:
layout.addWidget(...)
layout.addSpacer(...)
...
button.setLayout(layout)
Unfortunately the new layout is set, but the old one can still be seen. How do I solve this?
Based on your comments, you want to delete the items in the widget, not the layout. QLayout::takeAt returns a QLayoutItem*. Thus, you are looping through the widget's layout and deleting the layout items, but not the widgets that were added to the layout items. As a test, you might try the following instead:
while(!layout.isEmpty())
{
delete layout.itemAt(0)->widget();
delete layout.takeAt(0);
}
However, this isn't what I would consider a good long-term design. There may be a few special cases where this is the best method, but I would recommend looking into using a stacked widget or something similar to switch back and forth between the widgets presented, rather than destroy and recreate a whole array of widgets in a button. Alternately, consider two different buttons, and destroy and reinsert just the button rather than the contents of the button.
You could try doing
delete button.layout();
before setting the new layout.
Alternatively, you can just add the widgets etc to the existing layout (and not set a new layout then).
[Edit]
As long as you only use a pointer on the old layout, this should work:
QLayout* layout = button.layout();
while( !layout->isEmpty() )
{
delete( layout->takeAt( 0 ) );
}
layout->addWidget(...)
layout->addSpacer(...)
// do not call button.setLayout()
[Edit2]
If this is only an update problem you can try
button->update();
QApplication::processEvents( QEventLoop::IgnoreUserInputEvents );

How to turn on line number tooltip while scrolling infragistics ultrawebgrid

I once saw this feature in action but I don't know how to turn it on. The grid can show a tooltip with the current row number (or row ID) while dragging the scrollbar. This helps you to stop the scroll in the right place. I'm assuming some property will turn this on, but I can't find it.
Maybe it is also dependent on the scroll mode?
UPDATE:
In the image below you can see an example of the tooltip I'm looking for. This is displayed while the scrollbar is being dragged (up or down). The number in the tooltip is the row number (you can't see it in this image, way to the left in the grid). This is the same grid that I am using now. Just from a very old build of our product. Somehow this tooltip was turned off. And no one knows how to turn it back on :(
I'm pretty sure this is a built in feature of the ultrawebgrid. Not something that required extra coding.
alt text http://img138.imageshack.us/img138/6337/croppercapture.jpg
Right! Now that we've established that you have version 6.3, I've hopefully got a solution for you. I don't have 6.3 myself, but I've got a slightly later one that I think didn't have Virtual Scrolling added as a feature yet.
So try this code:
webgrid.DisplayLayout.XmlLoadOnDemandType = XmlLoadOnDemandType.Virtual;
This should automatically put a tooltip on the grid as you scroll down. Have a look here for a running sample... (and remember to choose the virtual option)
Here's hoping!
Rob G
I don't know if there's a UltraWebGrid property to simply turn on the behavior you're looking for. I almost suspect you experienced this feature in another application, perhaps not even a web based one (sorry!). I do however, know exactly what you're talking about.
As a work-around, I would suggest allowing the user to input the destination row number, and to simply "jump" to it, using this technique.
If that doesn't satisfy you, it may be possible to achieve this behavior with JavaScript. You would need to use something like this technique to get the information you need, estimate (or actually detect, if possible) the row number, and the rest is up to the GUI. I would go with the work-around described above though :)
I'm typing this from memory here as I don't have it installed on this machine and I haven't seen that setting before, but how about adding something like this to the InitializeRow event:
foreach (UltraGridCell cell in e.Row.Cells)
{
if(cell.Column.Key == "Topic") //from your grid above
cell.Title = cell.Row.Index;
}
The row object itself does not have a "Title" property from memory, but the cell does.
See if that works...
Regards,
Rob G
OK - I think I've found your illusive setting:
You can set the TipStyleScroll on the Override to Show on the Grid (this may be version dependant).
You can determine which field is displayed as the tooltip by using the ScrollTipField property of the band.
I did it like so:
myGrid.DisplayLayout.Override.TipStyleScroll = TipStyle.Show;
myTopBand.ScrollTipField = "Id";
...and it works like a charm!
If it's a really long list, sometimes setting the ScrollStyle to Deferred helps:
myGrid.DisplayLayout.ScrollStyle = ScrollStyle.Deferred;
Hope that helps...
Rob G
Once again - not sure which version you have, so to be safe here's somthing you can try from 2009 version:
myGrid.Behaviors.VirtualScrolling.Enabled = true;
myGrid.Behaviors.VirtualScrolling.TooltipVisibility = DefaultableBoolean.True;
If your scrolling mode is Deferred instead of Virtual, then the tooltip is normally enabled by default.
You can find full details about this feature here
Hope that helps,
Rob G

Resources