Results 1 to 6 of 6

Thread: how to dynamically add labels

  1. #1
    Join Date
    Oct 2009
    Location
    chennai,india
    Posts
    66
    Thanks
    18
    Qt products
    Qt4
    Platforms
    Windows

    Question how to dynamically add labels

    hi im new to qt.i installed qt 4.5 in windows xp sp2.i need to create one application in qt which is already present in c#.ok my problem is i need to create a set of labels in the form
    both horizontally and vertically.the noof labels to be displayed in the form is based on the query from the database...pls help me how to do..and im bit confused with layout ,boxlayout
    hboxlayout ..pls explain how to use those things...Moreover the how to place the labels in the desired position in the screen
    any help is highly regarded
    thanks and regards
    R.Mohanakrishnan

  2. #2
    Join Date
    Sep 2009
    Posts
    140
    Thanks
    4
    Thanked 17 Times in 17 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: how to dynamically add labels

    To begin easily layout mangement, just focus on QHBoxLayout, QVBoxLayout and QGridLayout.
    First of all, define your layout design that will receive widgets. You can nest layout into layouts.

    Simply add widget into layouts and let Qt display the widget for you.
    Use sequential QBoxLayout::addWidget for both Horizontal or Vertical layouts or QGridLayout::addWidget(row, col), to set a specified cell with a specified widget.

    The steps are the following :
    1. read the doc about layout
    2. create a layout
    3. set the layout for your widget with QWidget::setLayout 4. create your widgets
    5. add widgets to layout
    6. enjoy

    I let you looking for the right code instructions since it is not so difficult. The doc is your friend.

    Then you will notice that Qt dont mind about the order of setting layouts and adding widgets : either you can add widgets then set layout or set layout then add widget to it.

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

    mohanakrishnan (20th October 2009)

  4. #3
    Join Date
    Jan 2008
    Posts
    91
    Thanks
    8

    Default Re: how to dynamically add labels

    Dear Friends,
    I am working on a new project, I want to add a form some PushButtons dynamically, so I added a VerticalLayout to form, but My PushButton Class is derived from QPushButton,
    If I add QPush button to Layout I can see on form, but if I add MyButton it doesnt appear.

    THIS WORKS

    QWidget *window = new QWidget;
    QPushButton *button1 = new QPushButton("One");
    QPushButton *button2 = new QPushButton("Two");
    QPushButton *button3 = new QPushButton("Three");
    QPushButton *button4 = new QPushButton("Four");
    QPushButton *button5 = new QPushButton("Five");

    QHBoxLayout *layout = new QHBoxLayout;
    layout->addWidget(button1);
    layout->addWidget(button2);
    layout->addWidget(button3);
    layout->addWidget(button4);
    layout->addWidget(button5);


    THIS DOESNT

    QWidget *window = new QWidget;
    MyButton *button1 = new MyButton("One");
    MyButton *button2 = new MyButton("Two");
    MyButton *button3 = new MyButton("Three");
    MyButton *button4 = new MyButton("Four");
    MyButton *button5 = new MyButton("Five");

    QHBoxLayout *layout = new QHBoxLayout;
    layout->addWidget(button1);
    layout->addWidget(button2);
    layout->addWidget(button3);
    layout->addWidget(button4);
    layout->addWidget(button5);

  5. #4
    Join Date
    Sep 2009
    Posts
    140
    Thanks
    4
    Thanked 17 Times in 17 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: how to dynamically add labels

    May be something is missing in your button implementation, like calling base class method in overloaded one.
    Please provide your code.

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

    Default Re: how to dynamically add labels

    Your MyButton class is probably incorrect then.
    Your biological and technological distinctiveness will be added to our own. Resistance is futile.

    Please ask Qt related questions on the forum and not using private messages or visitor messages.


  7. #6
    Join Date
    Oct 2009
    Location
    chennai,india
    Posts
    66
    Thanks
    18
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: how to dynamically add labels

    hi
    thanks for this info because im newbie...
    i ll follow ur suggestions..
    thanks..

Similar Threads

  1. Adding widgets dynamically
    By miw in forum Qt Programming
    Replies: 1
    Last Post: 23rd July 2009, 11:31
  2. Replies: 0
    Last Post: 17th April 2009, 09:58
  3. Tick Labels for Slider
    By jcraig in forum Qt Tools
    Replies: 2
    Last Post: 9th August 2007, 18:21
  4. setting QTreeWidget vertical labels
    By hyling in forum Qt Programming
    Replies: 2
    Last Post: 10th January 2007, 19:53

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.