Results 1 to 4 of 4

Thread: Creating a new widget and apply it on another widget

  1. #1
    Join Date
    May 2011
    Posts
    27
    Thanks
    10
    Qt products
    Qt4
    Platforms
    Windows

    Question Creating a new widget and apply it on another widget

    Hello everyone,
    imagine that i have something like this in a class
    Qt Code:
    1. //...
    2. private:
    3. QWidget *widget;
    To copy to clipboard, switch view to plain text mode 
    and in one of the public functions i want to add other widgets like maybe a QPushButton and a QVBoxLayout. How can i do that?
    For the QPushButton i tried it this way:
    Qt Code:
    1. QPushButton *btn = new QPushButton("Hello");
    2. widget->layout()->addWidget(btn);
    To copy to clipboard, switch view to plain text mode 
    But the widget has currently no layout, so i cannot try it out...
    Is it possible to do it this way, and how can i apply a layout to the widget?

  2. #2
    Join Date
    Oct 2010
    Location
    Poland
    Posts
    26
    Thanks
    4
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: Creating a new widget and apply it on another widget

    Write more code. You should use a name of class that have a widget. Where you use a code with QPushButton?

  3. #3
    Join Date
    Mar 2009
    Location
    Brisbane, Australia
    Posts
    7,734
    Thanks
    13
    Thanked 1,610 Times in 1,537 Posts
    Qt products
    Qt4 Qt5
    Platforms
    Unix/X11 Windows
    Wiki edits
    17

    Default Re: Creating a new widget and apply it on another widget

    But the widget has currently no layout, so i cannot try it out...
    It isn't magic, you have to set one: QWidget::setLayout()
    Lots more in the trusty manual

  4. #4
    Join Date
    Jun 2007
    Location
    India
    Posts
    1,042
    Thanks
    8
    Thanked 133 Times in 128 Posts
    Qt products
    Qt3 Qt4 Qt/Embedded
    Platforms
    MacOS X Unix/X11 Windows

    Default Re: Creating a new widget and apply it on another widget

    the widget has no layout, so probably your child widgets are manually managed for resize. For widgets without layouts, you should pass the parent widget pointer to the child widget's constructor

    pushButton = new QPushButton("Hello",this);

Similar Threads

  1. Help me on creating a List Widget...
    By Bong.Da.City in forum Newbie
    Replies: 50
    Last Post: 11th September 2010, 14:51
  2. How to apply a QStyle to a widget
    By Luc4 in forum Qt Programming
    Replies: 2
    Last Post: 14th March 2010, 18:55
  3. Creating an OSX-like dock widget
    By k2 in forum Qt Programming
    Replies: 0
    Last Post: 1st June 2009, 22:16
  4. Replies: 1
    Last Post: 8th January 2009, 20:56
  5. Creating a widget on a QGraphicsView
    By maverick_pol in forum Qt Programming
    Replies: 4
    Last Post: 9th August 2007, 17:54

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.