My ScoreBoard inherits QMainWindow()
-
Hello.. Not to sound vague, but what is it with this TK? I keep getting this warning about trying to add a layout to class ScoreBoard when it already has one, a friend discovered that QMainWindow() has a special layout, he said to get rid of this warning is to create a CentralWidget of QWidget type, then add my Layout to that widget, did this, still getting same warning, can somebody explain a different way?
[code]
/* ScoreBoard QMainWindow() */
QWidget *cw; // cw == Central Widget
cw = new QWidget(this);
setCentralWidget(cw);
cw->setLayout(mainLayout); // Note: Not looking at my source, cannot remember where I put it earlier when I got that Seg Fault, I'm not mistaken, this is the proper location.
[/code]
[code]
/* The Layout code for QMainWindow */
QVBoxLayout *mainLayout;
mainLayout = new QVBoxLayout(this);[/code]
Thanks for the help.
[edit : fixed typo in title, Eddy]
-
Yes, QMainWindow already has a layout, which contains places for different elements (central widget, menu bar, status bar, north/south/east/west areas etc).
To show something in main window, you create a widget, and place it to main window with functions like [url=http://doc.qt.nokia.com/stable/qmainwindow.html#setCentralWidget]setCentralWidget()[/url], [url=http://doc.qt.nokia.com/stable/qmainwindow.html#setCorner]setCorner()[/url], and so on.
-
[quote author="mkoskim" date="1319199023"]Yes, QMainWindow already has a layout, which contains places for different elements (central widget, menu bar, status bar, north/south/east/west areas etc).
To show something in main window, you create a widget, and place it to main window with functions like setCentralWidget(), setCorner(), and so on.
[/quote]I'm trying to create my own custom Layout for advanced features..
-
[quote author="RichardM198030" date="1319199139"]
I'm trying to create my own custom Layout for advanced features..[/quote]You create the layout to your custom widget, and place that widget to main window:
[code]
QWidget *mainwidget = new QWidget;
mainwidget->setLayout(new MyCustomLayout);mainwindow->setCentralWidget(mainwidget);
[/code] -
[quote author="mkoskim" date="1319199272"][quote author="RichardM198030" date="1319199139"]
I'm trying to create my own custom Layout for advanced features..[/quote]You create the layout to your custom widget, and place that widget to main window:
[code]
QWidget *mainwidget = new QWidget;
mainwidget->setLayout(new MyCustomLayout);mainwindow->setCentralWidget(mainwidget);
[/code][/quote]Oooh, so I have to create 2 QWidgets then?
-
[quote author="RichardM198030" date="1319199600"]
Oooh, so I have to create 2 QWidgets then?
[/quote]Yes, you create one QMainWindow, and you place your custom QWidget on it (QMainWindow::setCentralWidget, except if you want to place your custom widget to e.g. some dockable areas).
-
[quote author="mkoskim" date="1319200495"][quote author="RichardM198030" date="1319199600"]
Oooh, so I have to create 2 QWidgets then?
[/quote]Yes, you create one QMainWindow, and you place your custom QWidget on it (QMainWindow::setCentralWidget, except if you want to place your custom widget to e.g. some dockable areas).[/quote]
LOL, sorry, I confused ya, I meant, I have to make 1 QWidget *cw; and a 2Nd QWidget *mainWIdget?
-
[quote author="RichardM198030" date="1319200911"]
LOL, sorry, I confused ya, I meant, I have to make 1 QWidget *cw; and a 2Nd QWidget *mainWIdget?
[/quote]No, one widget is enough. You place it to your main window. This is a wild guess, but what if you inherit your ScoreBoard from QWidget, and use just plain QMainWindow to show it?
[code]
class ScoreBoard : public QWidget { ... }...
main()
{
QMainWindow *mainwindow = new QMainWindow;
mainwindow->setCentralWidget(new ScoreBoard);
...
}
[/code] -
[quote author="mkoskim" date="1319202757"][quote author="RichardM198030" date="1319200911"]
LOL, sorry, I confused ya, I meant, I have to make 1 QWidget *cw; and a 2Nd QWidget *mainWIdget?
[/quote]No, one widget is enough. You place it to your main window. This is a wild guess, but what if you inherit your ScoreBoard from QWidget, and use just plain QMainWindow to show it?
[code]
class ScoreBoard : public QWidget { ... }...
main()
{
QMainWindow *mainwindow = new QMainWindow;
mainwindow->setCentralWidget(new ScoreBoard);
...
}
[/code]
[/quote]Just came with something different too.. I can keep my cw widget, make a mainwidget, add the layout to mainwidget, add the mainwidget to cw, and add cw to the ScoreBoard class, =).