Qt Dialog on Mac OS X behaving strangely...
-
Hello,
I created an inherited QDialog class to create a custom about box.
On Windows the dialog window loads fine but on Mac OS X it looks like my QTabWidget object is interfering with something.
You can see a comparison below:
Mac OS X:
!http://s3.postimg.org/gj3baar77/Screen_Shot_2015_02_16_at_2_43_59_PM.png(Mac Os X Bad Image...)!
Windows:
!http://s21.postimg.org/jn47rajqf/Windows_Image.png(Windows Good)!
Code for construction of class
@
QTAboutApplicationDialog::QTAboutApplicationDialog(QWidget *parent) :
QDialog(parent),
ui(new Ui::QTAboutApplicationDialog)
{
ui->setupUi(this);QLabel* logoLabel = new QLabel(); logoLabel->setStyleSheet(tr("background-image: url(Logos/Logo.png); background-repeat: no-repeat; background-position: center;")); QHBoxLayout* applicationInfoLayout = new QHBoxLayout(); QLabel* lblApplicationName = new QLabel(); lblApplicationName->setText(tr("Application Name: <B>") + QApplication::applicationDisplayName() + tr("</B>")); QLabel* lblApplicationVersion = new QLabel(); lblApplicationVersion->setText(tr("Application Version: <B>") + QApplication::applicationVersion() + tr("</B>")); applicationInfoLayout->addWidget(lblApplicationName); applicationInfoLayout->addWidget(lblApplicationVersion); std::string strLicenseText; std::ifstream LicenseFileStream("License/Copyright.htm", std::ios::in); if (LicenseFileStream.is_open()){ std::string Line = ""; while (getline(LicenseFileStream, Line)) strLicenseText += "\n" + Line; LicenseFileStream.close(); } QTextEdit* txtCopyRightNotice = new QTextEdit(); txtCopyRightNotice->setText(QString::fromStdString(strLicenseText)); txtCopyRightNotice->setReadOnly(true); QScrollArea* scrollLicense = new QScrollArea(); scrollLicense->setWidgetResizable(true); scrollLicense->setWidget(txtCopyRightNotice); QTabWidget* mainTabWidget = new QTabWidget(); QVBoxLayout* primaryLayout = new QVBoxLayout(); primaryLayout->addWidget(logoLabel); primaryLayout->addLayout(applicationInfoLayout); primaryLayout->addWidget(mainTabWidget); mainTabWidget->addTab(scrollLicense, tr("Copyright")); setLayout(primaryLayout); logoLabel->setMinimumHeight(183);
}
@ -
Could you post a larger Mac picture? It's hard to see what's on it.
But for now a couple of pointers:-
Don't split text inside tr because it makes it pretty much useless. How would you translate "</B>" or how would you put the bold text in front in some other language? Do this instead:
@
tr("Application Name: <b>%1</b>").arg(qApp->applicationDisplayName())
@
This way the whole thing can be translated and app name can be placed somewhere else if needed by some language. -
It's disrupting to mix frameworks. You're using Qt already anyway so instead of using iostreams and converting std::string to QString consider using QFile. It has a readAll() method so you don't need to read line by line, and you won't be converting. It's less code too.
-
QTextEdit is scrollable so I don't see a need for a QScrollArea there. You can put the textedit directly into the tab. As a bonus - maybe this will fix the issue?
-
-
Oh, ok. Did you create the dialog using the Qt Creator wizard? If so then it creates a dialogs that already has some layout and buttons (Ok/ Cancel).
You are then setting your own layout on the dialog but it doesn't remove the buttons. It's the same on windows, just that they probably hide under the tab widget.
If you're not using the default layout created by the wizard or the buttons then remove them in the form editor.
-
[quote author="Chris Kawa" date="1424128388"]Could you post a larger Mac picture? It's hard to see what's on it.
[/quote]Done.
[quote author="Chris Kawa" date="1424128388"]
But for now a couple of pointers:- Don't split text inside tr because it makes it pretty much useless. How would you translate "</B>" or how would you put the bold text in front in some other language? Do this instead:
@
tr("Application Name: <b>%1</b>").arg(qApp->applicationDisplayName())
@
This way the whole thing can be translated and app name can be placed somewhere else if needed by some language.
[/quote]
Good tip; I didn't realize that would be problematic; just a programming habit of mine.
[quote author="Chris Kawa" date="1424128388"]
- It's disrupting to mix frameworks. You're using Qt already anyway so instead of using iostreams and converting std::string to QString consider using QFile. It has a readAll() method so you don't need to read line by line, and you won't be converting. It's less code too.
[/quote]
Changed; I am used to using std-style code a lot so that is how I read from files. Will use Qt as much as I can going forward when programming with Qt.
[quote author="Chris Kawa" date="1424128388"]
- QTextEdit is scrollable so I don't see a need for a QScrollArea there. You can put the textedit directly into the tab. As a bonus - maybe this will fix the issue?[/quote]
Changed; I'll see how it works.
- Don't split text inside tr because it makes it pretty much useless. How would you translate "</B>" or how would you put the bold text in front in some other language? Do this instead:
-
I sure did use the dialog creation wizard. Will make the adjustments and then see how it works.
[quote author="Chris Kawa" date="1424129119"]Oh, ok. Did you create the dialog using the Qt Creator wizard? If so then it creates a dialogs that already has some layout and buttons (Ok/ Cancel).
You are then setting your own layout on the dialog but it doesn't remove the buttons. It's the same on windows, just that they probably hide under the tab widget.
If you're not using the default layout created by the wizard or the buttons then remove them in the form editor.[/quote]
-
The contents of the UI file would be helpful.
Likely the UI file already contains a layout for the dialog so the following line would replace it:
@
setLayout(primaryLayout);
@The UI file likely have at least two buttons (labeled 'OK' and 'Cancel') whether you created them or they were automatically created as part of the dialog.
-
Making the suggestions from Chris Kawa and Rondog worked out; especially deleting the default buttons placed in the window by the form builder.
Thank you!