Results 1 to 5 of 5

Thread: Widget Promotion

  1. #1
    Join Date
    Oct 2011
    Posts
    48
    Thanks
    6
    Qt products
    Qt4 Qt/Embedded
    Platforms
    Unix/X11 Windows

    Default Widget Promotion

    I am using a stackedWidget on my mainwindow . On this stackwidget I want same (frame ) on two pages. So I thought of creating a widget (frame ) and promoting the frames on these two pages to the custom one. Actually I need to connect some signals from mainwindow to this widget(frame) . As an example if I check a checkbox on Mainwindow , I want the pushbutton to be enabled on both pages. How can I connect the signal from mainwindow to the widget (frame) ? Please anyone help me..

  2. #2
    Join Date
    Mar 2011
    Location
    Hyderabad, India
    Posts
    1,882
    Thanks
    3
    Thanked 452 Times in 435 Posts
    Qt products
    Qt4 Qt5
    Platforms
    MacOS X Unix/X11 Windows
    Wiki edits
    15

    Default Re: Widget Promotion

    Tricky

    There are more than couple of ways, I suggets this (to keep things simple)

    1. As you already have frame class, have custom slots in fame to trigger the checkbox etc.
    2. Now create the pages (frames) dynamically from mainwindow, so the mainwindow will have frame widget handle(s).
    3. Connect the same signal of mainwindow to same slot of two (both) frame instances

    I hope it is clear that pages (frame) will no more be created from designer.

    Now as I said there are other ways like, create farmes from designer and get the handle for them from stackedwidget indexOf... or similar API, but this is subjected to the restriction that all the widgets in the stacked widget will be frames.
    When you know how to do it then you may do it wrong.
    When you don't know how to do it then it is not that you may do it wrong but you may not do it right.

  3. #3
    Join Date
    Oct 2011
    Posts
    48
    Thanks
    6
    Qt products
    Qt4 Qt/Embedded
    Platforms
    Unix/X11 Windows

    Default Re: Widget Promotion

    Thanks for reply ... Actually I want to create similar 16 pages with so many widgets like checkboxes. I want to connect the checkbox of 16 pages to some signal from one different page. For this I need to connect each and every checkbox separately to the signal. This is taking much time . If I create instance for the frame class on each page , again I need to connect all the checkboxes separately . So can you suggest me any other method ?


    One more thing ,

    relayFrame = new Frame();
    ui->tabWidget->insertWidget(5,relayFrame);
    ui->tabWidget->insertWidget(6,relayFrame);


    Can I use the same object of one class as widget on two different pages of tab or stackedwidget??

    Please help...

  4. #4
    Join Date
    Mar 2011
    Location
    Hyderabad, India
    Posts
    1,882
    Thanks
    3
    Thanked 452 Times in 435 Posts
    Qt products
    Qt4 Qt5
    Platforms
    MacOS X Unix/X11 Windows
    Wiki edits
    15

    Default Re: Widget Promotion

    One more thing ,

    relayFrame = new Frame();
    ui->tabWidget->insertWidget(5,relayFrame);
    ui->tabWidget->insertWidget(6,relayFrame);


    Can I use the same object of one class as widget on two different pages of tab or stackedwidget??
    NO. A widget object can live on only stackedwidget/tab page at any given point in time. It can be moved onto the different stackedwidget/tab page, note that moving the widget object will remove itself from the previous stackedwidget/tab page.

    Check this example
    Attached Files Attached Files
    Last edited by Santosh Reddy; 30th January 2013 at 07:20.
    When you know how to do it then you may do it wrong.
    When you don't know how to do it then it is not that you may do it wrong but you may not do it right.

  5. The following user says thank you to Santosh Reddy for this useful post:

    A9am (6th February 2013)

  6. #5
    Join Date
    Oct 2011
    Posts
    48
    Thanks
    6
    Qt products
    Qt4 Qt/Embedded
    Platforms
    Unix/X11 Windows

    Default Re: Widget Promotion

    Hi,

    Thank You for your reply..


    Added after 1 48 minutes:


    Hi ,

    I have a mainwindow in which i have one spinbox ,button and a frame . If i press button ,I want to add as many buttons as i select in spinbox ,say 5, to the frame with a layout. My code



    MainWindow::MainWindow(QWidget *parent) :
    QMainWindow(parent),
    ui(new Ui::MainWindow)
    {
    ui->setupUi(this);


    layout = new QVBoxLayout;
    ui->frame->setLayout(layout);

    connect(ui->pushButton,SIGNAL(clicked()),this,SLOT(getvalue() ));


    }

    MainWindow::~MainWindow()
    {
    delete ui;
    }


    void MainWindow::getvalue()
    {

    qDebug() << "value "<<ui->spinBox->value();
    int i = ui->spinBox->value();

    QPushButton *button[5];

    for(int j=0;j<i;j++)
    {
    button[j] = new QPushButton;
    layout->addWidget(button[j]);
    }



    }



    But this code adds each button to the frame every time i press button as I am not deleting the widget from the layout or frame. How can I do this ?? Please help..
    Last edited by A9am; 6th February 2013 at 11:39.

Similar Threads

  1. QWidget promotion with child widgets
    By Phlucious in forum Qt Programming
    Replies: 3
    Last Post: 22nd February 2012, 07:41
  2. Replies: 8
    Last Post: 2nd February 2012, 19:52
  3. Replies: 2
    Last Post: 23rd January 2012, 17:06
  4. Replies: 1
    Last Post: 23rd June 2011, 23:09
  5. promotion problems with designer
    By szisziszilvi in forum Qt Programming
    Replies: 3
    Last Post: 26th April 2011, 08:27

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.