qt 自繪界面實現思路


界面靠拖動也可以,自繪也可以,設置無標題效果,標題欄必須是自繪的。qt界面有三種widget、dialog、mainwindow,思路基本一致,

1.自繪界面要設置標題欄隱藏

 
        
this->setWindowFlags(Qt::FramelessWindowHint | Qt::WindowSystemMenuHint | Qt::WindowMinMaxButtonsHint);
setAttribute(Qt::WA_TranslucentBackground);

2.設置窗體大小
this->setFixedSize(850,600);

3.widget和dialog基本實現一致,mainwindow本身已經有界面布局,稍微有些差別
先說不太一樣的,因為,mainwindow是由centralwidget和menubar和statusbar組成,組件、布局只可以在centralwidget內布置
  centerWindow = new QWidget;
  centerWindow->setSizePolicy(QSizePolicy::Expanding,QSizePolicy::Expanding);
  centerWindow->setObjectName(tr("centerWindow"));
 this->setCentralWidget(centerWindow);

 4.新建mainLayout(垂直布局),titleLayout,toolLayout,contentLayout,statusLayout,都是水平布局,每個布局添加好自己的組件,然后mainLayout布局把所有布局添加進來(addLayout),最后centerWindow把主布局添加         進來,centerWindow->setLayout(mainLayout);

  最終代碼大概是這樣的:

      

   
  titleLayout->addWidget(minButton);
  ...

  mainLayout = new QVBoxLayout();
    mainLayout->addLayout(titleLayout);
    mainLayout->addLayout(toolLayout);
    mainLayout->addLayout(contentLayout);
    mainLayout->addStretch();
    mainLayout->addLayout(status_layout);
    mainLayout->setSpacing(0);
    mainLayout->setContentsMargins(0, 0, 0, 0);
    centerWindow->setLayout(mainLayout);

 





免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM