Results 1 to 6 of 6

Thread: Function returning a QHBoxLayout

  1. #1
    Join Date
    Aug 2010
    Posts
    5
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Question Function returning a QHBoxLayout

    Hi, I want to do the following dialog:



    now I have done a function which create an entry item, but I don't know how return "widget" or "layout" to allow to add them to a QGridLayut...

    Qt Code:
    1. ??? GestioneClienteDialog::creaItemCliente(Domain::Persona c)
    2. {
    3. ??? widget = new ???; // widget or layout? what type? and how?
    4.  
    5. QHBoxLayout *boxEsterno = new QHBoxLayout();
    6. QVBoxLayout *boxContenitore = new QVBoxLayout();
    7. QHBoxLayout *boxDati = new QHBoxLayout();
    8.  
    9. QRadioButton *radio = new QRadioButton();
    10. QLabel *piva = new QLabel();
    11. QLabel *ragionesociale = new QLabel();
    12. QLabel *cognome = new QLabel();
    13. QLabel *nome = new QLabel();
    14. QLabel *indirizzo = new QLabel();
    15. QLabel *citta = new QLabel();
    16.  
    17. piva->setVisible(false);
    18.  
    19. piva->setText(c.piva());
    20. ragionesociale->setText(c.ragionesociale());
    21. cognome->setText(c.cognome());
    22. nome->setText(c.nome());
    23. indirizzo->setText(c.indirizzo());
    24. citta->setText(c.citta());
    25.  
    26. boxDati->addWidget(cognome);
    27. boxDati->addWidget(nome);
    28. boxDati->addWidget(indirizzo);
    29. boxDati->addWidget(citta);
    30.  
    31. boxContenitore->addWidget(ragionesociale);
    32. boxContenitore->addLayout(boxDati);
    33.  
    34. boxEsterno->addWidget(radio);
    35. boxEsterno->addLayout(boxContenitore);
    36.  
    37. widget->addWHAT(boxEsterno);
    38.  
    39. return widget;
    40. }
    To copy to clipboard, switch view to plain text mode 


    Thank you...

  2. #2
    Join Date
    Jan 2006
    Location
    Germany
    Posts
    4,380
    Thanks
    19
    Thanked 1,005 Times in 913 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows Symbian S60
    Wiki edits
    5

    Default Re: Function returning a QHBoxLayout

    It depends on how you want use it, but normally a widget is a good choice:
    Qt Code:
    1. QWidget* GestioneClienteDialog::creaItemCliente(Domain::Persona c)
    2. {
    3. QWidget* widget = new QWidget();
    4. //your code like
    5. widget->setLayout(boxEsterno)
    6. return widget;
    To copy to clipboard, switch view to plain text mode 
    Make sure that the receiver sets a valid parent for the widget.

  3. #3
    Join Date
    Apr 2010
    Posts
    9
    Thanked 3 Times in 1 Post
    Qt products
    Qt4 Qt/Embedded
    Platforms
    MacOS X Unix/X11 Windows

    Default Re: Function returning a QHBoxLayout

    Hi aomegax, I think all depends of what you wish to do with the returned type. If you are going to used as a regular QWidget and add it to another Layout (for example, QHBoxLayout or QVBoxLayout, etc), then of course you should return a QWidget. But, if you wish to use the returned type as a container of QWidgets, or you are going to add more elements after call creaItemCliente; would be better to use a Layout as the returned type.

    It's also important to note, the Parent-Child relationship between the components. Remember that if you call setLayout on a QWidget, all the components that you added to the QWidget via the QLayout, will be childs of the QWidget, not the QLayout.
    So, it would be thoughtful if you have into account both of the recommendation I gave you.

    I Hope this answers your question.

  4. #4
    Join Date
    Aug 2010
    Posts
    5
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: Function returning a QHBoxLayout

    Hi, thanks everybody to help me...
    I have used both your informations...
    At the end I have used layout because I must add them to a gridLayout...
    now only one question...If I do:

    Qt Code:
    1. while (grid->layout()->count() > 0)
    2. {
    3. QLayoutItem *l = grid->layout()->takeAt(0);
    4. if (l->layout())
    5. {
    6. delete l->layout();
    7. }
    8. delete l;
    9. }
    To copy to clipboard, switch view to plain text mode 
    why the items added before isn't deleted? how can I do to clear gridLayout from all the layouts which I add in a first moment?


    however thank you!

  5. #5
    Join Date
    Aug 2010
    Posts
    5
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: Function returning a QHBoxLayout

    can anybody help me?

  6. #6
    Join Date
    May 2009
    Location
    Canada
    Posts
    163
    Thanks
    7
    Thanked 20 Times in 20 Posts
    Qt products
    Qt4 Qt5
    Platforms
    MacOS X Windows Android

    Default Re: Function returning a QHBoxLayout


Similar Threads

  1. class QHBoxLayout
    By csvivek in forum Installation and Deployment
    Replies: 2
    Last Post: 10th April 2008, 07:57
  2. zero'ing margin in a qhboxlayout
    By illuzioner in forum Qt Programming
    Replies: 3
    Last Post: 2nd July 2007, 10:54
  3. Replies: 12
    Last Post: 14th June 2006, 09:24
  4. QHBoxLayout Problem
    By Seema Rao in forum Qt Programming
    Replies: 5
    Last Post: 29th April 2006, 15:51
  5. Replies: 3
    Last Post: 19th April 2006, 20:53

Tags for this Thread

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.