PDA

View Full Version : Widget Promotion



A9am
29th January 2013, 13:06
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..:(

Santosh Reddy
29th January 2013, 14:20
Tricky :eek:

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.

A9am
30th January 2013, 06:31
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 ? :confused:


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...

Santosh Reddy
30th January 2013, 07:57
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

A9am
6th February 2013, 12:39
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..:)