2018年1月21日 星期日

對話框的基本概念

<定義>
對話框是GUI程序中不可或缺的重要組成部分

通常對話框會是一個頂層的窗口(出現在程序的最上層)

<常見目的>
實現短期任務, 簡單的用戶交戶作用

<模式分類>

對話框可分為兩種常見的模式:
1.模態對話框:
會阻塞同一個app的其他窗口的輸入(白話文:用戶不能對除了這個窗口外的其他窗口進行操作)

2.非模態對話框:
用戶可以在顯示剛對話窗口同時繼續對其app其他窗口進行操作

<模態又可分兩種級別>
1.應用程式app級別(默認預設):
用戶必須先與該對話框進行交互直到關閉該對話框, 然後才能訪問
應用程序中其他的窗口

2.窗口級別:
僅阻塞與對話框關聯的窗口(其父窗口), 依然允許用戶與該應用程序中其
他的窗口做交互

<實際應用>
1.模態app級別>>使用QDialog::exec

2.模態窗口級別>>使用QDialog::open

3.非模態對話框>>使用QDialog::show


菜單控制疊層窗體

<操作>
之前已經介紹過如何使用(清單列表)選項來控制(疊層窗體)
現在我們要利用<菜單>的選項來做控制~
下面是主程式的.cpp
菜單選項的觸發信號要使用QAction類中的觸發triggered
先去.h宣告一個私有信號槽的函數void modbuscontrl()
使用新宣告的函示這裡是叫modbuscontrl()來做控制
將觸發後要變更的窗體序號寫入setCurrentIndex(1)



#include "menuwindow.h"
#include "ui_menuwindow.h"
#include <QSerialPortInfo>
#include <QComboBox>
#include <QSpinBox>
#include <QAction>
#include <QStackedLayout>


MenuWindow::MenuWindow(QWidget *parent) :
    QMainWindow(parent),

    ui(new Ui::MenuWindow),
    m_transactionCount(0)
{
    ui->setupUi(this);
  
    connect(ui->actionModbus, &QAction::triggered, this, &MenuWindow::modbuscontrl);

}
void MenuWindow::modbuscontrl(){

   ui->stackedWidget_mode->setCurrentIndex(1);

}

 
MenuWindow::~MenuWindow()
{
    delete ui;
}


2018年1月17日 星期三

疊層窗體

<目標>

<實作>
控件效果是由兩個元件組成:
1.清單元件listWidget(左邊的清單效果)
2.疊層窗體stackedWidget(右邊的頁面會根據左邊的選項作切換)
3.各項元件拉好位子後, 只需要在主窗的.cpp中修改構造函數~
4.利用connect()將兩個元件對應的序號連接起來

#include "onlywindow.h"
#include "ui_onlywindow.h"
#include "QStackedWidget"
#include "QListWidget"
#include "QLabel"

onlywindow::onlywindow(QWidget *parent) :
    QMainWindow(parent),
    ui(new Ui::onlywindow)
{
    ui->setupUi(this);
    connect(ui->listWidget,SIGNAL(currentRowChanged(int)),
ui->stackedWidget,SLOT(setCurrentIndex(int)));


}

onlywindow::~onlywindow()
{
    delete ui;
}

void onlywindow::on_pushButton_clicked()
{
    QString a=ui->lineEdit->text();
    ui->gg->setText(a);

}

抽屜效果

抽屜效果函式

<目標>

<實作>
本專案使用.ui檔來建模(較有效率)

需要元件:
1.widget (拉出一個區域部件)
2.PushButton (打開抽屜後出現的按鈕)
3.ToolBox (抽屜效果)

步驟:
拉出一個區域widget >>將ToolBox 拖曳至其區域中>>再將PushButton 拖曳至ToolBox 中
(過程完全不需要編寫.cpp或是.h)

調整:
對ToolBox ()的屬性作變更
屬性解釋:
currentIndex:變數指引(0代表第一個抽屜的編號)
currentItemText:變數項目本文(代表抽屜顯示的名稱)
currentItemName:變數項目名稱
currentItemIcon:變數項目頭像
currentItemToolTip:變數項目提示(就是滑鼠放在上面時會出現類似註解的提示)
tabSpacing:下拉空間(觸發抽屜效果後往下出現的空間大小值)

2018年1月16日 星期二

進度條函式用法

進度條函式用法

<建置環境>
建模工具為: Qt Creator 4.5.0
作業系統: window 7
編譯環境: MingW 32

<類別函式>
QProgressBar()

<目標>

<實作>
1.新建專案,本專案使用主視窗為QMainWindow
窗類別名稱設為onlywindow

2.照圖建立好自己的.ui

3.進入onlywindow.h 將要用到的函式引用incloude
再將私有變數的信號槽建好


//onlywindow.h
#ifndef ONLYWINDOW_H
#define ONLYWINDOW_H
#include <QMainWindow>
#include <QProgressBar>
#include <QPushButton>
#include <QLabel>

namespace Ui {

class onlywindow;

}


class onlywindow : public QMainWindow

{

    Q_OBJECT

public:

    explicit onlywindow(QWidget *parent = 0);

    ~onlywindow();


private slots:

    void startProgress();

    void resetProgress();

private:

    Ui::onlywindow *ui;


};

#endif // ONLYWINDOW_H

4.進入onlywindow.cpp來完成主函式
使用connect()函式將2個按鈕與進度條功能連結在一起
startProgress()為在按下按鈕<開始>後,進度條要執行的函式
resetProgress()為在按下按鈕<清空>後,進度條要執行的函式
#include "onlywindow.h"
#include "ui_onlywindow.h"



onlywindow::onlywindow(QWidget *parent) :
    QMainWindow(parent),
    ui(new Ui::onlywindow)
{
    ui->setupUi(this);

    connect(ui->start, SIGNAL(clicked()), this, SLOT(startProgress()));
    connect(ui->reset, SIGNAL(clicked()), this, SLOT(resetProgress()));

}

void onlywindow::startProgress(){

    for(int i=0;i<=1000;i++){
        ui->PBar->setValue(i);
        QString str=QString("%1").arg(i);
        str="複製數量: "+ str;
        ui->label01->setText(str);
    }
}

void onlywindow::resetProgress(){
    ui->PBar->setValue(0);
    ui->label01->setText("複製數量: 0");
}

onlywindow::~onlywindow()
{
    delete ui;
}

主視窗架構

首先:
主使窗的類別名稱我們訂為onlywindow 專案產生後生成3個文件夾 
先看到自動生成的<onlywindow.h>
#ifndef ONLYWINDOW_H
#define ONLYWINDOW_H

#include <QMainWindow>

namespace Ui {
class onlywindow;
}

class onlywindow : public QMainWindow
{
    Q_OBJECT

public:
    explicit onlywindow(QWidget *parent = 0);
    ~onlywindow();

private:
    Ui::onlywindow *ui;
};

#endif // ONLYWINDOW_H


接著看到基本的main.cpp主體
基本上這裡的變數會依據你所訂的框架自動生成
EX: onlywindow w;
比較常來這裡做調整的多是跟視窗顯示的順序與權限有關西
EX: w.show();
#include "onlywindow.h"
#include <QApplication>

int main(int argc, char *argv[])
{
    QApplication a(argc, argv);
    onlywindow w;
    w.show();

    return a.exec();
}
在看到onlywindow.cpp
#include "onlywindow.h"
#include "ui_onlywindow.h"

onlywindow::onlywindow(QWidget *parent) :
    QMainWindow(parent),
    ui(new Ui::onlywindow)
{
    ui->setupUi(this);
  
}

onlywindow::~onlywindow()
{
    delete ui;
}

可以看到在一開頭因為之前在.h中已經將onlywindow主窗類別名稱加入Ui空間中
所以我們現在能使用
onlywindow::onlywindow(QWidget *parent): 來當作類似Main()的視窗函式

2017年4月7日 星期五

【台北站前】勝博殿日式炸豬排(新光三越)

【勝博殿】-日式炸豬排

店家資訊在最下方~

這間勝博殿是位於台北車站對面的新光三越樓上(12樓)

終於有機會寫到這間口碑非常好的日式炸豬排

既然來了就是要點他們家的豬排啊@@!!!









餐廳的裝潢分常有日式的氣氛


我們先從前菜介紹

身為一家專業的日式炸豬排基本的新鮮高麗菜絲無限量供應
也是很正常的 @@

3樣小菜+2種米飯 也是無限量供應
左邊那個是黑豆!!!日本的抗老化聖品

重點來了 !!!他們家的豬排在部位上大致分為兩種~

1.里脊豬排(吃起來比較柴) 

2.腰內豬排(脂肪比例較高吃起來較嫩)

上圖是各一半@@!!!這樣兩種都吃的到瞜~



如果你想吃比較飽  建議點 鐵板類套餐(豬跟雞都能選) 


 以下是炸物拼盤類

可樂餅~

繽紛野菜組合炸物!!!

有炸香菇~炸杏孢菇~炸肉片包番茄


飯後甜點~冰淇淋巧克力布朗尼@@!!!




店家資訊

店名: 勝博殿  (新光三越台北站前店)

地址: 臺北市中正區忠孝西路一段66號新光三越台北站前店

電話: 02-2371-0828

營業時間: 11:00–15:30, 17:00–22:00