PDA

View Full Version : Add QTextEdit in a Help Menu



stbb24
7th June 2012, 14:42
I have a Help Menu and under the help menu i have help, and about. Now when the user clicks the help menu a new window should pop out containing all the help details of the program.

I have this code so far for the help action.




void MainWindow::on_action_Help_triggered()
{
ui->newWindow = new QWidget();
ui->newWindow->show();
ui->newWindow->setFixedSize(350, 200);
ui->newWindow->setWindowTitle("Help Menu");

QTextEdit *textEdit = new QTextEdit;
textEdit->setText("sample");
textEdit->show();

}


Unfortunately my code is showing me this. 4 windows, 2 for the help menu and 2 for the textEdit.
7813

How can I connect the textEdit to the widget so that it will only be in that widget and not as a separate window?And why is it showing two instances of the help menu and the textEdit when I don't even have a loop to show them twice?

Added after 6 minutes:

So to make my life a little bit easier i just decided to do this



void MainWindow::on_action_Help_triggered()
{
QTextEdit *textEdit = new QTextEdit;
textEdit->setFixedSize(350, 200);
textEdit->setWindowTitle("Help Menu");
textEdit->setReadOnly(TRUE);
textEdit->setText("sample");
textEdit->show();
}


But for some reason how come when i click the help option it's showing me two instances of textEdit?
7814

amleto
7th June 2012, 15:41
widgets appear in their own window unless they have a parent.

you can set parents via 2 ways - directly set parent*, or add widget to a layout, then set the layout on the parent widget.

If your window shows up twice, it will be because you have connected the signal/slot twice.


*this can be done two ways - by constructor parent argument or by setParent()

stbb24
7th June 2012, 16:01
Thanks! I already got it thanks for the clue about the connect/slot signals :)

Different question...

How can I display my program in a specific area? Because everytime i run the program sometimes it displays in the left side, right side, bottom side of my monitor. So how can I set it's display position in a fix area so that everytime I run it, it will only display itseld the area that I specified (for ex: in the center of the monitor)

amleto
7th June 2012, 16:05
widget->move(x,y);

first google result:
http://www.qtforum.org/article/14204/how-to-center-a-widget-on-the-screen-in-qt-4-before-show-is-called.html

stbb24
8th June 2012, 01:33
Thanks amleto :) it work