qt创建界面的过程和方法(qt实战记录简单窗体处理)
1.vs创建qt Widget项目,目录结构如下:
2.添加静态资源:在项目文件夹中新建静态资源文件夹,并添加资源内容。
vs中qrc文件中添加静态资源:
3.创建头文件topDeskPaper.h,抽取信息,代码如下:
创建topDeskPaper.cpp初始化窗体属性,
窗体初始化设置,根据注释可知其意,代码如下:
// 初始化数据
void TopDeskPaper::init()
{
// 设置logo
this->setWindowIcon(QIcon("./img/wangyicloud.png"));
// 窗口最大化
QDesktopWidget *desktopWidget = QApplication::desktop();
int windowWidth = desktopWidget->width(); // 获取窗体宽度
int windowHeight = desktopWidget->height(); // 获取窗体高度
//this->setWindowState(Qt::WindowMaximized); // 设置最大化
this->setFixedSize(windowWidth, windowHeight); // 设置最大化
// 隐藏窗口标题栏
this->setWindowFlags(Qt::FramelessWindowHint);
// 设置窗体名称及编码[存在乱码]
//this->setWindowTitle(QString::fromLocal8Bit("我的桌面"));
this->setWindowTitle(QString::fromLocal8Bit("JunitPro"));
// 去除背景
this->setAttribute(Qt::WA_TranslucentBackground);
// 设置透明
this->setWindowOpacity(0.5);
// 设置系统托盘
QSystemTrayIcon *systemTrayIcon = new QSystemTrayIcon;
systemTrayIcon->setIcon(QIcon("./img/wangyicloud.png"));
// 设置托盘菜单
QMenu *trayMenu = new QMenu;
// 1.添加托盘菜单QAction
QAction *settingAction = new QAction(QString::fromLocal8Bit("设置"));
settingAction->setIcon(QIcon("./img/close.png"));
trayMenu->addAction(settingAction);
// 2.添加托盘退出菜单
QAction *closeAction = new QAction(QString::fromLocal8Bit("退出"));
closeAction->setIcon(QIcon("./img/eleExit.png"));
trayMenu->addAction(closeAction);
// 添加托盘菜单
systemTrayIcon->setContextMenu(trayMenu);
// 展示托盘面板
systemTrayIcon->show();
// 退出菜单事件
QObject::connect(closeAction, SIGNAL(triggered()), this, SLOT(Quit()));
}
格式化的截图如下:
4.创建ui文件,代码如下:
<UI version="4.0" >
<class>TopDeskPaperClass</class>
<widget class="QMainWindow" name="TopDeskPaperClass" >
<property name="objectName" >
<string notr="true">TopDeskPaperClass</string>
</property>
<property name="geometry" >
<rect>
<x>0</x>
<y>0</y>
<width>600</width>
<height>400</height>
</rect>
</property>
<property name="windowTitle" >
<string>TopDeskPaper</string>
</property> <widget class="QMenuBar" name="menuBar" />
<widget class="QToolBar" name="mainToolBar" />
<widget class="QWidget" name="centralWidget" />
<widget class="QStatusBar" name="statusBar" />
</widget>
<layoutDefault spacing="6" margin="11" />
<pixmapfunction></pixmapfunction>
<resources>
<include location="topDeskPaper.qrc"/>
</resources>
<connections/>
</UI>
格式化截图如下:
,
免责声明:本文仅代表文章作者的个人观点,与本站无关。其原创性、真实性以及文中陈述文字和内容未经本站证实,对本文以及其中全部或者部分内容文字的真实性、完整性和原创性本站不作任何保证或承诺,请读者仅作参考,并自行核实相关内容。文章投诉邮箱:anhduc.ph@yahoo.com