這仍然有點神祕。我使用了樣式表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