PDA

View Full Version : QTextEdit is too small in QMainWindow



icx
6th September 2010, 01:21
I believe the picture speaks for itself. :) It's a very simple program with a major issue!

Moreover, if I try to add a button and use the QVBoxLayout the button is added over the QTextEdit in the same corner. :(

LE: Here's the image http://img713.imageshack.us/img713/6827/qtextbox.png

Zlatomir
6th September 2010, 01:30
When you use QMainWindow, you can't use layouts directly. That is because the QMainWindow already has a layout (In the output of your Qt Creator you get a message about this issue)

To solve this you can create a QWidget that you use like a container for your layout (with all the other widgets) and use the setCentralWidget() (http://doc.qt.nokia.com/4.6/qmainwindow.html#setCentralWidget) (pass a pointer to the "container" QWidget)

SixDegrees
6th September 2010, 01:30
You need to add your widgets to a layout.

icx
9th September 2010, 11:28
When you use QMainWindow, you can't use layouts directly. That is because the QMainWindow already has a layout (In the output of your Qt Creator you get a message about this issue)

To solve this you can create a QWidget that you use like a container for your layout (with all the other widgets) and use the setCentralWidget() (http://doc.qt.nokia.com/4.6/qmainwindow.html#setCentralWidget) (pass a pointer to the "container" QWidget)

Damn, I always forget that, thanks! So I tried to make two additional widgets, but it seems that the lower one is not visible. Here's the code: http://yfrog.com/nfwidgetp

Moreover, ButtonWidget's parent is MainWidget. MainWidget's parent is that default QMainWindow. Is this "parenting" OK?

Lykurg
9th September 2010, 11:32
first attach your images here on the forum, not on 3rd party sites, second please also post your code that it is not only viewable on your image.

Solution: create your ButtonsWidget on the heap, not on the stack. Because right now it gets deleted after the scope reaches it end. So before it is being displayed it has already been deleted. (Basic C++ stuff.)