WPF 下有Telerik可以很方便的实现Office的样式。习惯了Office2007下蓝色的调调,所以找了QtitanRibbon进行Qt下的开发
可参考的文章很少,对于一个Qt新手很是折磨,琢磨调试了两天总算运行起来的。
只针对入门者,觉得有帮助可以点一个赞。
记录如下:
开发环境:
- qt-opensource-windows-x86-5.14.2
- QtitanRibbonInstaller5.9.0_mingw

-
Qt中只安装了mingw 64相关的可选项
image.png
-
Qt安装完成后,定义一下环境变量
image.png
-
QtitanRibbonInstaller5.9.0_mingw 安装过程中会要求定位qmake路径,先正确选择
image.png
代码结构
-
定义文件 HelloTitan.cpp
image.png
- 文件内容为
#include <QtitanRibbon.h>
#include <QApplication>
#include <QHBoxLayout>
int main(int argc, char *argv[])
{
QApplication app(argc, argv);
RibbonBar* m_dlgRibbonBar = new RibbonBar();
m_dlgRibbonBar->addPage(QObject::tr("Home"));
QHBoxLayout *layout = new QHBoxLayout;
layout->addWidget(m_dlgRibbonBar);
QWidget *window = new QWidget;
window->setWindowTitle("Hello Titan");
window->setLayout(layout);
window->show();
return app.exec();
}
-
在当前目录打开 cmd ,并运行 qmke -project 生成 HelloTitan.pro
image.png
-
HelloTitan.pro文件的内容为
######################################################################
# Automatically generated by qmake (3.1)
######################################################################
TEMPLATE = app
TARGET = HelloTitan
INCLUDEPATH += .
# You can make your code fail to compile if you use deprecated APIs.
# In order to do so, uncomment the following line.
# Please consult the documentation of the deprecated API in order to know
# how to port your code away from it.
# You can also select to disable deprecated APIs only up to a certain version of Qt.
#DEFINES += QT_DISABLE_DEPRECATED_BEFORE=0x060000 # disables all the APIs deprecated before Qt 6.0.0
# Input
SOURCES += HelloTitan.cpp
- 修改HelloTitan.pro添加相关引用
######################################################################
# Automatically generated by qmake (3.1)
######################################################################
TEMPLATE = app
TARGET = HelloTitan
INCLUDEPATH += .
QT += core gui
greaterThan(QT_MAJOR_VERSION, 4): QT += widgets
include(C:/Qt/Developer Machines/QtitanRibbon5.9.0/src/shared/qtitanribbon.pri)
# You can make your code fail to compile if you use deprecated APIs.
# In order to do so, uncomment the following line.
# Please consult the documentation of the deprecated API in order to know
# how to port your code away from it.
# You can also select to disable deprecated APIs only up to a certain version of Qt.
#DEFINES += QT_DISABLE_DEPRECATED_BEFORE=0x060000 # disables all the APIs deprecated before Qt 6.0.0
# Input
SOURCES += HelloTitan.cpp
LIBS += -L$$QTITAN_LIB_PATH/ -llibQtitanRibbon5 -llibQtitanBase1
-
生成Make 文件
image.png
image.png
-
编译
image.png
-
运行 release 下的文件报错
image.png
-
将HelloTitan.exe拷贝到 QtitanRibbon的bin目录就行了
image.png
- 修改HelloTitan.cpp 改变样式
#include <QtitanRibbon.h>
#include <QApplication>
#include <QHBoxLayout>
int main(int argc, char *argv[])
{
QApplication app(argc, argv);
Office2016Style* style = new Office2016Style();
style->setTheme(Office2016Style::Colorful);
qApp->setStyle(style);
RibbonBar* m_dlgRibbonBar = new RibbonBar();
m_dlgRibbonBar->addPage(QObject::tr("Home"));
QHBoxLayout *layout = new QHBoxLayout;
layout->addWidget(m_dlgRibbonBar);
QWidget *window = new QWidget;
window->setWindowTitle("Hello Titan");
window->setLayout(layout);
window->show();
return app.exec();
}
-
运行效果
image.png
网友评论