Results 1 to 13 of 13

Thread: QWidget exactly above QWidget

  1. #1
    Join Date
    Jun 2006
    Posts
    32
    Thanks
    1
    Thanked 1 Time in 1 Post

    Question QWidget exactly above QWidget

    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.

  2. #2
    Join Date
    Jan 2006
    Location
    Munich, Germany
    Posts
    4,709
    Thanks
    21
    Thanked 418 Times in 411 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows

    Default Re: QWidget exactly above QWidget

    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.
    ==========================signature=============== ==================
    S.O.L.I.D principles (use them!):
    https://en.wikipedia.org/wiki/SOLID_...iented_design)

    Do you write clean code? - if you are TDD'ing then maybe, if not, your not writing clean code.

  3. #3
    Join Date
    Jun 2006
    Posts
    32
    Thanks
    1
    Thanked 1 Time in 1 Post

    Default Re: QWidget exactly above QWidget

    Quote Originally Posted by high_flyer View Post
    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.

  4. #4
    Join Date
    Jan 2006
    Location
    Munich, Germany
    Posts
    4,709
    Thanks
    21
    Thanked 418 Times in 411 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows

    Default Re: QWidget exactly above QWidget

    can you show us your code?
    ==========================signature=============== ==================
    S.O.L.I.D principles (use them!):
    https://en.wikipedia.org/wiki/SOLID_...iented_design)

    Do you write clean code? - if you are TDD'ing then maybe, if not, your not writing clean code.

  5. #5
    Join Date
    Jun 2006
    Posts
    32
    Thanks
    1
    Thanked 1 Time in 1 Post

    Default Re: QWidget exactly above QWidget

    this is the code :

    Qt Code:
    1. QWidget * w =myBackendSelectionWidget->myBackendComboBox->parentWidget();
    2. QLayout * layout = myBackendSelectionWidget->myBackendComboBox->layout();
    3. myBackendComboBox = new QComboBox(w);
    4. myBackendComboBox->setGeometry(/*132,8,80,20*/myBackendSelectionWidget->myBackendComboBox->geometry());
    5. myBackendComboBox->show();
    To copy to clipboard, switch view to plain text mode 

    myBackendSelectionWidget - the widget that holds the old combobox

    thats the result:



    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

  6. #6
    Join Date
    Jan 2006
    Location
    Munich, Germany
    Posts
    4,709
    Thanks
    21
    Thanked 418 Times in 411 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows

    Default Re: QWidget exactly above QWidget

    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.
    ==========================signature=============== ==================
    S.O.L.I.D principles (use them!):
    https://en.wikipedia.org/wiki/SOLID_...iented_design)

    Do you write clean code? - if you are TDD'ing then maybe, if not, your not writing clean code.

  7. #7
    Join Date
    Jun 2006
    Posts
    32
    Thanks
    1
    Thanked 1 Time in 1 Post

    Default Re: QWidget exactly above QWidget

    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....

  8. #8
    Join Date
    Jan 2006
    Location
    Munich, Germany
    Posts
    4,709
    Thanks
    21
    Thanked 418 Times in 411 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows

    Default Re: QWidget exactly above QWidget

    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.
    ==========================signature=============== ==================
    S.O.L.I.D principles (use them!):
    https://en.wikipedia.org/wiki/SOLID_...iented_design)

    Do you write clean code? - if you are TDD'ing then maybe, if not, your not writing clean code.

  9. #9
    Join Date
    Jun 2006
    Posts
    32
    Thanks
    1
    Thanked 1 Time in 1 Post

    Default Re: QWidget exactly above QWidget

    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.

  10. #10
    Join Date
    Jan 2006
    Location
    Munich, Germany
    Posts
    4,709
    Thanks
    21
    Thanked 418 Times in 411 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows

    Default Re: QWidget exactly above QWidget

    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.
    ==========================signature=============== ==================
    S.O.L.I.D principles (use them!):
    https://en.wikipedia.org/wiki/SOLID_...iented_design)

    Do you write clean code? - if you are TDD'ing then maybe, if not, your not writing clean code.

  11. #11
    Join Date
    Jun 2006
    Posts
    32
    Thanks
    1
    Thanked 1 Time in 1 Post

    Default Re: QWidget exactly above QWidget

    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

  12. #12
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,363
    Thanks
    3
    Thanked 5,012 Times in 4,791 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: QWidget exactly above QWidget

    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.

  13. #13
    Join Date
    Jan 2006
    Location
    Munich, Germany
    Posts
    4,709
    Thanks
    21
    Thanked 418 Times in 411 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows

    Default Re: QWidget exactly above QWidget

    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)
    ==========================signature=============== ==================
    S.O.L.I.D principles (use them!):
    https://en.wikipedia.org/wiki/SOLID_...iented_design)

    Do you write clean code? - if you are TDD'ing then maybe, if not, your not writing clean code.

Similar Threads

  1. Reuse a Qwidget with a QStackWidget
    By ucomesdag in forum Qt Programming
    Replies: 4
    Last Post: 25th April 2007, 02:47
  2. Replies: 4
    Last Post: 24th April 2007, 13:18
  3. Replies: 3
    Last Post: 8th March 2007, 14:54
  4. Transparent QWidget on QGLWidget
    By showhand in forum Qt Programming
    Replies: 2
    Last Post: 27th November 2006, 01:00
  5. Replies: 1
    Last Post: 2nd May 2006, 21:11

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Digia, Qt and their respective logos are trademarks of Digia Plc in Finland and/or other countries worldwide.