C++ GUI Qt 編程(第二版)第8章 Diagram_1(實現主對話方塊)

來源:互聯網
上載者:User

  這個程式有4個類,其中還有一個form這個程式還算是比較複雜的了,但是作者提供的原始碼在xp系統、Qt4.7、windows and linux的環境下,可以添加node類,但是需要選中兩個node才能串連,但是串連後去沒有辦法在和連接線一起拖動,實際顯示節點和連線是分離的。下面就這個程式和這個程式的問題做一個全面的分析

實現主對話方塊:

main.cpp的原始碼為:

#include <QApplication>


#include "Diagram.h"

int main(int argc, char *argv[])
{
    QApplication app(argc, argv);
    Diagram view;
    view.show();
    return app.exec();
}

Diagramwindow.h的原始碼為:

#ifndef DIAGRAM_H

#define DIAGRAM_H

#include<QMainWindow>

class QAction;
class QGraphicsItem;
class QGraphicsScene;
class QGraphicsView;

class Diagram : public QMainWindow
{
    Q_OBJECT

public:
    Diagram();
private:
    QGraphicsScene *scene;
    QGraphicsView *view;
};

#endif // DIAGRAM_H

Diagramwindow.cpp的原始碼為:

#include<QtGui>

#include "Diagram.h"

Diagram::Diagram()
{
    scene = new QGraphicsScene(0, 0, 600, 500); new a scene

    view = new QGraphicsView;new a view
    view->setScene(scene);set the vscene in the view
    view->setDragMode(QGraphicsView::RubberBandDrag);set the view mode
    view->setRenderHints(QPainter::Antialiasing
                         | QPainter::TextAntialiasing);
    view->setContextMenuPolicy(Qt::ActionsContextMenu);
    setCentralWidget(view);
}
這些最簡單的代碼,構成了一個最簡單的windows的對話方塊,編譯通過的結果如下
 

 


聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.