PopUp Window. How to show full text content and two other questions
Question
I created a popup window like this:
QFileInfo FileA = "AAA";
QFileInfo FileB = "BBB";
if (fileA.exists() == false & (fileB.exists() == false))
{
QFrame* PopupWin = new QFrame(this, Qt::Popup | Qt::Window );
PopupWin->setGeometry(450,450, 400, 200);
PopupWin->setLineWidth ( 3 );
PopupWin->setMidLineWidth ( 1 );
PopupWin->setFrameStyle ( QFrame::Box | QFrame::Raised);
QLabel *message = new QLabel(PopupWin);
message->setAlignment(Qt::AlignHCenter | Qt::AlignVCenter);
message->setGeometry(100,50, 200, 100);
message->setText("blaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa"
"bluuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuu"
"bliiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiii"
"bleeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeee"
"bloooooooooooooooooooooooooooooooooooooooooooooo");
PopupProzess->show();
}
I have three questions:
- When the window pops up I can't see the whole text, just a part of the first line of the label. How can I show the whole text?
- The frame is closed when clicking anywhere at the screen. How do disable this "anywhere-click-close" and create a pushbutton or a kind of cross that closes the frame/window?
- How do I fit the text right into the label and the label right into the frame?
I searched in the Qt Doc and also googled, but did not find the solutions. greetings
Solution
Why are you creating a QFrame
? What you want is a QDialog
.
- Use the
QtDesigner
in order to design your dialog - Implement a class inheriting from
QDialog
corresponding to the dialog you designed - Use
exec
in order to show it modally.
This way your code will be cleaner and much easier to read.
QDialog* pMyDialog = new MyDialog(this); // you have to delete it later...
if (fileA.exists() == false && (fileB.exists() == false))
{
pMyDialog->exec();
}
Also there is no reason to hardcode the geometry of a UI element. This is what QtDesigner
is for.
Concerning the label, as spbots already answered you have to set the wordWrap
property.
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow