转载

Qt图标的显示问题

#ifndef MAINWINDOW_H
#define MAINWINDOW_H

#include <QMainWindow>
#include <QAction>

class MAinWindow:public QMainWindow
{
    Q_OBJECT
public:
    MAinWindow(QWidget *parent=0);
    ~MAinWindow();

private:
    void open();
    QAction *openAction;
};
#endif
 
#include "mainwindow.h"
 
#include <QMenuBar>
#include <QMessageBox>
#include <QStatusBar>
#include <QToolbar>
#include <QDialog>
 
MAinWindow::MAinWindow(QWidget *parent):QMainWindow(parent)
{
    setWindowTitle(tr("Main Window"));
 
    openAction=new QAction(QIcon(":/images/doc-open"),tr("&Open..."),this);//我添加的图标显示不出来
    openAction->setShortcuts(QKeySequence::Open);
    openAction->setStatusTip(tr("Open a file"));
 
    connect(openAction,&QAction::triggered,this,&MAinWindow::open);
 
    QMenu *file=menuBar()->addMenu(tr("&File"));
    file->addAction(openAction);
 
    QToolBar *toolBar=addToolBar(tr("&File"));
    toolBar->addAction(openAction);
 
    QStatusBar *statusbar=statusBar();
    statusbar->addAction(openAction);
 
}
 
MAinWindow::~MAinWindow()
{
}
 
void MAinWindow::open()
{
    //QDialog dialog;
    //dialog.setWindowTitle(tr("hello,dialog"));
    //dialog.exec();
    QMessageBox::information(this,tr("Information"),tr("open"));

}

#include<QApplication>
#include "mainwindow.h"
 
 
int main(int argc,char *argv[])
{
    QApplication app(argc,argv);
 
    MAinWindow win;
 
    win.show();
 
    return app.exec();
}
 

我有个问题就是为什么我添加的图标显示不出来!求大神看一下!

 
 

                    
正文到此结束
本文目录