这仍然有点神秘。我使用了样式表Qt示例应用程序,它演示了* .ui和* .qss文件的用法。Qt:* .ui文件和* .qss文件如何与MainWindow类实例关联?
他们有一个主窗口类,它是在* .ui中设计的。然而,代码根本不包含任何* .ui或* .qss的引用,但它们在运行时关联。我无法理解如何。
这是初始化主窗口的代码;
int main(int argc, char *argv[])
{
Q_INIT_RESOURCE(stylesheet);
QApplication app(argc, argv);
MainWindow window;
window.show();
return app.exec();
}
这是主窗口的代码...
的* .h:
#ifndef MAINWINDOW_H
#define MAINWINDOW_H
#include <QtGui>
#include "ui_mainwindow.h"
class StyleSheetEditor;
class MainWindow : public QMainWindow
{
Q_OBJECT
public:
MainWindow();
private slots:
void on_editStyleAction_triggered();
void on_aboutAction_triggered();
private:
StyleSheetEditor *styleSheetEditor;
Ui::MainWindow ui;
};
#endif
*的.cpp:
include <QtGui>
#include "mainwindow.h"
#include "stylesheeteditor.h"
MainWindow::MainWindow()
{
ui.setupUi(this);
ui.nameLabel->setProperty("class", "mandatory QLabel");
styleSheetEditor = new StyleSheetEditor(this);
statusBar()->addWidget(new QLabel(tr("Ready")));
connect(ui.exitAction, SIGNAL(triggered()), qApp, SLOT(quit()));
connect(ui.aboutQtAction, SIGNAL(triggered()), qApp, SLOT(aboutQt()));
}
void MainWindow::on_editStyleAction_triggered()
{
styleSheetEditor->show();
styleSheetEditor->activateWindow();
}
void MainWindow::on_aboutAction_triggered()
{
QMessageBox::about(this, tr("About Style sheet"),
tr("The <b>Style Sheet</b> example shows how widgets can be styled "
"using <a href=\"http://qt.nokia.com/doc/4.5/stylesheet.html\">Qt "
"Style Sheets</a>. Click <b>File|Edit Style Sheet</b> to pop up the "
"style editor, and either choose an existing style sheet or design "
"your own."));
}
任何人都可以解释为什么它与唤醒我的资源中* .ui文件的内容?
哇。谢谢。对于来自“普通”C++/GDI/Win32或C#/ .NET的用户来说,这是一种全新的思维方式,但我会掌握它的。 – JasonGenX 2011-01-26 20:31:39