PDA

View Full Version : QWidget exactly above QWidget



Equilibrium
24th October 2007, 09:35
Hi all,

I can access a widget which holds a label and a combo box.
I have also a pointer to the combobox.
I need to do the folowings:

1. create new combobox.
2. place it exactly above the widget combobox.

pos , geomtry etc, returns 0,0 of the x,y of the old combobox.

How can i place the new combobox to cover exactly the old combobox.
please assist.

high_flyer
24th October 2007, 09:40
this whole idea sounds bad.
If you tell us what it is you want to achieve we will probably be able to offer a better way of solving it.

To your question:
If both combo boxes are children of the same parent widget just use the geometry of one for the other.

Equilibrium
24th October 2007, 10:16
this whole idea sounds bad.
If you tell us what it is you want to achieve we will probably be able to offer a better way of solving it.

To your question:
If both combo boxes are children of the same parent widget just use the geometry of one for the other.

I've tried to use the geometry function but since the qcombobox of the original widget is layed it's position is different than the one recived via the geometry function.

The reason i need to do this all issue is because i need to chnage the data displayed in the combo box , but if i do this that it influance other stuff wgich use the data stored in the combo box/

therefore i need to create a copy of the combobox above the original one and just display different data.

no, geometry doesn't work.

high_flyer
24th October 2007, 10:31
can you show us your code?

Equilibrium
24th October 2007, 11:22
this is the code :



QWidget * w =myBackendSelectionWidget->myBackendComboBox->parentWidget();
QLayout * layout = myBackendSelectionWidget->myBackendComboBox->layout();
myBackendComboBox = new QComboBox(w);
myBackendComboBox->setGeometry(/*132,8,80,20*/myBackendSelectionWidget->myBackendComboBox->geometry());
myBackendComboBox->show();


myBackendSelectionWidget - the widget that holds the old combobox

thats the result:

http://static.zooomr.com/images/3577420_5a91063075_m.jpg

the left combobox is the new one.

What i want is to place it exactly on top pf the right one (the old combobox) , and exactly the same width and height.

10x

high_flyer
24th October 2007, 11:43
Oh, now I see, you are using a layout.
The layout prevent it from you, since it already has a widget in that location.
I'd suggest you try to hide the original combo box before you add the new one.
If that doesn't help, I think you will have to give up on using a layout there.

Maybe someone else can have a better idea.

Can't you instead only load that "meta data" in the orginal combo?
This way you wont change the original data, and would actually be a cleaner solution.

Equilibrium
24th October 2007, 11:48
no i can't , the changed data of the original combo box screw something else.
It's strange the layout function of the original combobox returns null....

high_flyer
24th October 2007, 12:07
no i can't , the changed data of the original combo box screw something else.
I could not make sense of what you wrote here, in regard to using a copy of the data.
If you don't want to change the actual data, why do you need to use the original combo box on the original data?
Just use the one combo box you have, but with a copy of the data, not the original - this way you don't touch the original data, unless you explicitly do so later, for example in a slot after changes have been made in the copy.

Equilibrium
24th October 2007, 12:49
the problem is that not only I use this combo...
Other code (which ican't access ) uses this data also , and probably depend on the structure of the data , thats why i can't manipulate the data of this combo box.

high_flyer
24th October 2007, 13:43
Other code (which ican't access ) uses this data also
If other code only access the data (and not the combo), then you have no problem (as far as I can tell from your explanations so far) since you can manipulate a copy of the data in your combo - thus leaving the original data intact.

Equilibrium
25th October 2007, 09:36
Done!!

1. Hide the original combobox.
2. search the children of the parent widget;
3. located the layout.
4. removed the original combobox.
5. entered the new combobox.

Works perfectly

wysota
25th October 2007, 10:13
Can't you just change the data for a moment? If you used a model to contain your data it'd be only two lines of code - both calling QComboBox::setModel() with different data models. If that's not an option for you because of some reasons, it probably means your design is wrong and maybe you should consider changing it.

high_flyer
25th October 2007, 10:28
Done!!

1. Hide the original combobox.
2. search the children of the parent widget;
3. located the layout.
4. removed the original combobox.
5. entered the new combobox.

Works perfectly
heh...
1+2+3+4+5 == load a copy of data to original combo (same effect, less work) ;)