#include "Export.h"
#include "LoadCellSite.h"
#include <QtWidgets/QApplication>
#include <QDialog>
#include <QVBoxLayout>
#include <QGroupBox>
#include <QRadioButton>
#include <QCheckBox>
#include <QLabel>
#include <QImage>
#include <QScrollArea>
#include <QHBoxLayout>
#include <QToolBox>
#include <QToolButton>
#include <QTabWidget>
#include <QPushButton>
#include <QListWidget>
#include <QStackedWidget>
#include <QMdiArea>
#include <QMdiSubWindow>
#include <QTextEdit>
#include <QDockWidget>
#include <QMainWindow>
#if 0
int main(int argc, char *argv[])
{
QApplication a(argc, argv);
//Export w;
//w.show();
//LoadCellSite l;
//l.show();
return a.exec();
}
#endif
//groupbox实例
#if 0
int main(int argc, char *argv[])
{
QApplication a(argc, argv);
QDialog w;
QGroupBox *group = new QGroupBox("option");
group->setTitle("sdsss");
QRadioButton *radio1 = new QRadioButton("banana");
QRadioButton *radio2 = new QRadioButton("pear");
QRadioButton *radio3 = new QRadioButton("apple");
radio1->setChecked(true);
QCheckBox *check = new QCheckBox("rice");
check->setChecked(true);
QVBoxLayout *vbox = new QVBoxLayout;
vbox->addWidget(radio1);
vbox->addWidget(radio2);
vbox->addWidget(radio3);
vbox->addWidget(check);
group->setLayout(vbox);
w.setLayout(vbox);
w.show();
return a.exec();
}
#endif
#if 0
//QScrollArea滚动区
int main(int argc, char *argv[])
{
QApplication a(argc, argv);
QWidget w;
QLabel *label = new QLabel(&w);
QImage image("G:\\QT\\QT所有组件继承情况.png");
QHBoxLayout *lay = new QHBoxLayout(&w);
label->setPixmap(QPixmap::fromImage(image));
//创建滚动区,
QScrollArea *scrollarea = new QScrollArea(&w);
//将Widget组件加入滚动区
scrollarea->setWidget(label);
//自动改变滚动区大小
scrollarea->setWidgetResizable(1);
//设置滚动区背景颜色
scrollarea->setBackgroundRole(QPalette::Dark);
lay->addWidget(scrollarea);
w.setLayout(lay);
w.show();
return a.exec();
}
#endif
#if 0
//QToolBox工具箱
class ToolBox : public QToolBox
{
// Q_OBJECT
public:
explicit ToolBox(QWidget *parent = 0);
private:
QToolButton *button1;
QToolButton *button2;
QToolButton *button3;
QToolButton *button11;
QToolButton *button12;
};
ToolBox::ToolBox(QWidget *parent) :
QToolBox(parent)
{
setWindowTitle("ToolBox");
//***************水果*****************
button1 = new QToolButton;
button1->setText("apple");
button1->setAutoRaise(true);
button1->setToolButtonStyle(Qt::ToolButtonFollowStyle);
button2 = new QToolButton;
button2->setText("banana");
button2->setAutoRaise(true);
button2->setToolButtonStyle(Qt::ToolButtonTextBesideIcon);
button3 = new QToolButton;
button3->setText("pear");
button3->setAutoRaise(true);
button3->setToolButtonStyle(Qt::ToolButtonTextBesideIcon);
//***************添加水果*****************
QGroupBox *group = new QGroupBox;
QVBoxLayout *layout = new QVBoxLayout(group);
layout->setMargin(10);
layout->setAlignment(Qt::AlignHCenter);
layout->addWidget(button1);
layout->addWidget(button2);
layout->addWidget(button3);
layout->addStretch();
//初始化电脑
button11 = new QToolButton;
button11->setText("HP");
button11->setAutoRaise(true);
button11->setToolButtonStyle(Qt::ToolButtonTextBesideIcon);
button12 = new QToolButton;
button12->setText("Lenovo");
button12->setAutoRaise(true);
button12->setToolButtonStyle(Qt::ToolButtonTextBesideIcon);
//***************添加电脑*****************
QGroupBox *group2 = new QGroupBox;
QVBoxLayout *layout2 = new QVBoxLayout(group2);
layout2->setMargin(10);
layout2->setAlignment(Qt::AlignHCenter);
layout2->addWidget(button11);
layout2->addWidget(button12);
layout2->addStretch();
this->addItem((QWidget*)group, "Fruits");
this->addItem((QWidget*)group2, "Computer");
}
int main(int argc, char *argv[])
{
QApplication a(argc, argv);
ToolBox toolbox;
toolbox.show();
return a.exec();
}
#endif
#if 0
//QTabWidget选项卡
int main(int argc, char *argv[])
{
QApplication a(argc, argv);
QTabWidget *tab = new QTabWidget;
//第一页
QWidget *w = new QWidget(tab);
QPushButton *button1 = new QPushButton("OK", w);
QPushButton *button2 = new QPushButton("NO", w);
QVBoxLayout *hlayout = new QVBoxLayout(w);
hlayout->addWidget(button1);
hlayout->addWidget(button2);
tab->addTab(w, "option1");
//第二页
QLabel *label = new QLabel("QT", tab);
tab->addTab(label, "option2");
tab->setWindowTitle("QTabWidget");
tab->setTabPosition(QTabWidget::South);
tab->show();
return a.exec();
}
#endif
#if 0
//QStackedWidget控件栈
//mainLayout->setMargin(30); //表示控件与窗体的左右边距
//mainLayout->setSpacing(40); //表示各个控件之间的上下间距
int main(int argc, char* argv[])
{
QApplication a(argc, argv);
QDialog w;
w.setWindowTitle("StackedWidget");
//设置列表框
QListWidget *leftlist = new QListWidget(&w);
leftlist->insertItem(0, "window1");
leftlist->insertItem(1, "window2");
leftlist->insertItem(2, "window3");
//设置堆栈窗体
QLabel *label1 = new QLabel("WindowTest1\n\tby liming");
QLabel *label2 = new QLabel("WindowTest2\n\tby liming");
QLabel *label3 = new QLabel("WindowTest3\n\tby liming");
QStackedWidget *stack = new QStackedWidget(&w);
stack->addWidget(label1);
stack->addWidget(label2);
stack->addWidget(label3);
//设置主窗体布局
QHBoxLayout *mainLayout = new QHBoxLayout(&w);
mainLayout->setMargin(5);
mainLayout->setSpacing(5);
mainLayout->addWidget(leftlist);
mainLayout->addWidget(stack, 0, Qt::AlignHCenter);
mainLayout->setStretchFactor(leftlist,8);
mainLayout->setStretchFactor(stack, 8);
w.connect(leftlist, SIGNAL(currentRowChanged(int)), stack, SLOT(setCurrentIndex(int)));
w.show();
return a.exec();
}
#endif
#if 0
//QFrame框架
int main(int argc, char *argv[])
{
QApplication a(argc, argv);
QWidget *win = new QWidget;
QLabel *label = new QLabel("Box");
QLabel *label1 = new QLabel("Panel");
QLabel *label2 = new QLabel("Winpanel");
QLabel *label3 = new QLabel("H line");
QLabel *label4 = new QLabel("V line");
QLabel *label5 = new QLabel("Styled Panel");
label->setFrameStyle(QFrame::Box | QFrame::Raised);
label->setLineWidth(2);
label1->setFrameStyle(QFrame::Panel | QFrame::Raised);
label1->setLineWidth(2);
label2->setFrameStyle(QFrame::WinPanel | QFrame::Raised);
label2->setLineWidth(2);
label3->setFrameStyle(QFrame::HLine | QFrame::Raised);
label3->setLineWidth(2);
label4->setFrameStyle(QFrame::VLine | QFrame::Raised);
label4->setLineWidth(2);
label5->setFrameStyle(QFrame::StyledPanel | QFrame::Sunken);
label5->setLineWidth(2);
QVBoxLayout *layout = new QVBoxLayout;
layout->addWidget(label);
layout->addWidget(label1);
layout->addWidget(label2);
layout->addWidget(label3);
layout->addWidget(label4);
layout->addWidget(label5);
win->setLayout(layout);
win->showMaximized();
return a.exec();
}
#endif
#if 0
//QWidget组件
int main(int argc, char *argv[])
{
QApplication a(argc, argv);
QMdiArea* mdi = new QMdiArea;
QMdiSubWindow* sub = new QMdiSubWindow;
QLabel *label = new QLabel("hello");
sub->setWidget(label);
sub->setAttribute(Qt::WA_DeleteOnClose);
mdi->addSubWindow(sub);
mdi->show();
return a.exec();
}
#endif
//QDockWidget停靠窗体
int main(int argc, char *argv[])
{
QApplication a(argc, argv);
QMainWindow w;
w.setWindowTitle("DockWindows");//设置主窗口标题栏文字
QTextEdit *te = new QTextEdit(&w); //定义一个QTextEdit对象作为主窗口
te->setText("Main Window");
te->setAlignment(Qt::AlignCenter);
w.setCentralWidget(te); //编辑框设置为主窗口的中央窗口
//停靠窗口1
QDockWidget *dock = new QDockWidget("DockWindow1", &w);
dock->setFeatures(QDockWidget::DockWidgetMovable);//可移动
dock->setAllowedAreas(Qt::LeftDockWidgetArea | Qt::RightDockWidgetArea);
QTextEdit *te1 = new QTextEdit();
te1->setText("Window1,The dock widget can be moved between docks and users");
dock->setWidget(te1);
w.addDockWidget(Qt::LeftDockWidgetArea, dock);
//停靠窗口2
dock = new QDockWidget("DockWindow2", &w);
dock->setFeatures(QDockWidget::DockWidgetClosable |
QDockWidget::DockWidgetFloatable);//可关闭、可浮动
QTextEdit *te2 = new QTextEdit();
te2->setText("Window2,The dock widget can be detac from the main window,""and float as an independent window,and can be closed");
dock->setWidget(te2);
w.addDockWidget(Qt::RightDockWidgetArea, dock);
//停靠窗口3
dock = new QDockWidget("DockWindow3", &w);
dock->setFeatures(QDockWidget::AllDockWidgetFeatures);//所有特性
QTextEdit *te3 = new QTextEdit();
te3->setText("Window3,The dock widget can be closed,moved,and float");
dock->setWidget(te3);
w.addDockWidget(Qt::RightDockWidgetArea, dock);
w.show();
return a.exec();
}