Results 1 to 2 of 2

Thread: Widgets Layout in a QToolBar.

  1. #1
    Join Date
    Jun 2008
    Location
    Rome, Italy
    Posts
    95
    Thanks
    19
    Thanked 2 Times in 2 Posts
    Qt products
    Qt4 Qt5
    Platforms
    MacOS X Unix/X11 Windows

    Default Widgets Layout in a QToolBar.

    Hi to all,
    I've inserted, via code, a QLabel and QLineEdit in a QToolBar as showed in the next screenshot:



    but I'd like to line up vertically both QLabel and QLineEdit:



    so I've tried the following code:

    Qt Code:
    1. void frmEntUsc::creaToolBar()
    2. {
    3. QLabel * lblRicerca;
    4. lblRicerca = new QLabel();
    5. lblRicerca->setText(QString::fromUtf8("Ricerca per Data: "));
    6. lblRicerca->setAlignment(Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter);
    7.  
    8. ricData = new QDateEdit();
    9. ricData->setMinimumSize(QSize(100, 20));
    10. ricData->setMaximumSize(QSize(100, 20));
    11. ricData->setWrapping(false);
    12. ricData->setFrame(true);
    13. ricData->setAlignment(Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter);
    14. ricData->setButtonSymbols(QAbstractSpinBox::UpDownArrows);
    15. ricData->setAccelerated(true);
    16. ricData->setCalendarPopup(true);
    17. ricData->setDate(QDate::currentDate());
    18.  
    19. ui.editToolBar->insertWidget(ui.action_Ricerca, lblRicerca);
    20. ui.editToolBar->insertWidget(ui.action_Ricerca, ricData);
    21. ui.editToolBar->insertSeparator(ui.action_Stampa);
    22.  
    23. vLayout = new QVBoxLayout();
    24. vLayout->addWidget(lblRicerca);
    25. vLayout->addWidget(ricData);
    26.  
    27. connect(ui.action_Ricerca, SIGNAL(triggered()),
    28. this, SLOT(appFiltro()));
    29.  
    30. connect(ricData, SIGNAL(dateChanged(QDate)),
    31. this, SLOT(cambioData(QDate)));
    32. }
    To copy to clipboard, switch view to plain text mode 

    but nothing happened!!!
    How can I line up those widgets?
    Attached Images Attached Images

  2. #2
    Join Date
    Jan 2008
    Location
    Poland
    Posts
    687
    Thanks
    4
    Thanked 140 Times in 132 Posts
    Qt products
    Qt4 Qt5
    Platforms
    Unix/X11 Windows

    Default Re: Widgets Layout in a QToolBar.

    nothing happened because you did not set the layout anywhere. just create one QWidget and set the layout to it and then add that widget (which will contain your 2 widgets) to the toolbar, instead of adding your 2 widgets separately.
    Qt Code:
    1. // remove these 2 lines
    2. //ui.editToolBar->insertWidget(ui.action_Ricerca, lblRicerca);
    3. //ui.editToolBar->insertWidget(ui.action_Ricerca, ricData);
    4.  
    5. . . .
    6.  
    7. QWidget *widget = new QWidget;
    8. widget->setLayout(vLayout);
    9. ui.editToolBar->insertWidget(ui.action_Ricerca, widget);
    To copy to clipboard, switch view to plain text mode 
    I would like to be a "Guru"

    Useful hints (try them before asking):
    1. Use Qt Assistant
    2. Search the forum

    If you haven't found solution yet then create new topic with smart question.

  3. The following user says thank you to faldzip for this useful post:

    cydside (27th June 2009)

Similar Threads

  1. Layout, widgets and resize questions
    By Carlsberg in forum Qt Programming
    Replies: 2
    Last Post: 26th June 2009, 12:49
  2. remove widgets from layout in run time
    By bindigi01 in forum Qt Programming
    Replies: 10
    Last Post: 6th June 2009, 22:36
  3. Replies: 1
    Last Post: 14th May 2009, 22:00
  4. Custom widgets in layout
    By Palmik in forum Newbie
    Replies: 11
    Last Post: 26th January 2009, 12:08
  5. Promoted widgets and layout boxes
    By notsonerdysunny in forum Qt Tools
    Replies: 3
    Last Post: 2nd May 2007, 14:15

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.