View Full Version : Open a window inside another window
passerb
17th October 2009, 13:04
Hello,
I'd like to know how can I open a window embedded in another one. More specifically I want to open a window in a determined part of another window when I click in a button. And I don't know what object I can use to open a window inside it.
Thank in advance
caduel
17th October 2009, 13:15
if 'window' means a Qt widget, have a look at QMdiArea
Peppy
17th October 2009, 13:27
If u means this:
class MainWindow : public QWidget
{
public:
MainWindow(QWidget *parent = 0);
private slots:
void newWindow();
private:
QWidget *newWindow;
};
MainWindow::MainWindow(QWidget *parent) : QWidget(parent)
{
QPushButton *n = new QPushButton("new Window");
n->show();
connect(n,SIGNAL(clicked()),this,SLOT(newWindow()) );
}
int main(int argv, char *argc[])
{
QApplication app(argv,argc);
MainWindow mW;
mW.show();
app.exec();
}
void MainWindow::newWindow()
{
newWindow = new QWidget;
newWindow->setGeometry(QRect(100,100,300,300));
newWindow->setWindowTitle("new Window");
newWindow->show();
}
...
passerb
17th October 2009, 19:03
Thank you for your answer. You help me a lot :)
passerb
18th October 2009, 00:51
I tried this by this way: (I'm using PyQt4)
- I generated a MainWindow using Qt Design with a widget object where I want to load another widget
- I generated a Widget using Qt Design with a simple button
Like this:
#class widget that I want to be loaded
class a(object):
def setupUi(self, Form):
Form.setObjectName("Form")
self.btModificar = QtGui.QPushButton(self.centralwidget)
self.btModificar.setGeometry(QtCore.QRect(280, 40, 91, 21))
self.toolBox.setCurrentIndex(0)
#class that I want to load the widget
class Ui_MainWindow(object):
def setupUi(self, MainWindow):
MainWindow.setObjectName("MainWindow")
self.centralwidget = QtGui.QWidget(MainWindow)
self.centralwidget.setObjectName("centralwidget")
self.btAdicionar = QtGui.QPushButton(self.centralwidget)
self.btAdicionar.setGeometry(QtCore.QRect(90, 40, 91, 21))
self.btAdicionar.setObjectName("btAdicionar")
self.widget = QtGui.QWidget(self.centralwidget)
self.widget.setGeometry(QtCore.QRect(160, 105, 811, 471))
self.widget.setObjectName("widget")
MainWindow.setCentralWidget(self.centralwidget)
QtCore.QObject.connect(self.btAdicionar, QtCore.SIGNAL("clicked()"), MainWindow.adicionar)
# thats the class that implements the Ui_MainWindow
class MainWindow (QMainWindow, Ui_MainWindow):
def __init__(self, parent=None):
super(MainWindow, self).__init__(parent)
self.setupUi(self)
def adicionar(self):
# here I want to load that widget named a
# I tried this:
# aa = a()
# self.widget.setParent(aa)
# self.widget.show()
# but it didnt work
Lykurg
18th October 2009, 07:19
Instead of positioning all your widgets yourself by using setGeometry, you should use layouts! It is much more easier that way. And to layouts you can easily add other widgets - even on runtime - using QLayout::addWidget().
passerb
18th October 2009, 13:24
I did it!! Thank you very much :)
I could using QLayout::addWidget() like you said :)
Powered by vBulletin® Version 4.2.5 Copyright © 2024 vBulletin Solutions Inc. All rights reserved.