当前位置:   article > 正文

基于cmake工程的Qt引入FluentUI库遇到的问题_fluentui qt

fluentui qt

FluentUI是github上一个开源的Qt组件库,作者设计了很多精美的控件,并且设计了一个精美的展示程序,引入该库可以避免我们重复造轮子,快速的提升界面的美观度,如何创建引入该工程是一个问题,本人花了一点时间,将此工程配置了起来。

本人使用了QQuickWidget引入了qml文件,并结合widgets程序进行Qt开发。

  • 下面是FluentUI的相关连接:

zhuzichu520/FluentUI: FluentUI for QML (github.com)


  • 下面是QQuickWidget的相关连接:

通俗易懂玩QT:QQuickWidget学习-CSDN博客

Qt之qml和widget混合编程调用_qml工程中,使用qwidget组件-CSDN博客


  • 以下是本人的环境信息:

操作系统:Ubuntu 20.04

Qt:6.5.3

cmake:3.20.0(FluentUI的要求,不能通过简单的修改FluentUI cmake工程来绕开检查,会报错)

cmake的参数信息(根据自己的环境来):

  1. -DCMAKE_GENERATOR:STRING=Ninja
  2. -DCMAKE_PREFIX_PATH:PATH=/home/xiaopeng-lee/Qt/6.5.3/gcc_64
  3. -DQT_DIR:PATH=/home/xiaopeng-lee/Qt/6.5.3/gcc_64/lib/cmake/Qt6
  4. -DQt6_DIR:PATH=/home/xiaopeng-lee/Qt/6.5.3/gcc_64/lib/cmake/Qt6
  5. -DQT_DIR:PATH=/home/xiaopeng-lee/Qt/6.5.3/gcc_64/lib/cmake/Qt6

一、首先我们创建一个基于cmake的widgets应用程序(只列了关键的)

二、接着我们编辑UI文件,将QQuickWidget拖入我们的界面中(按自己需求)

为了测试我们简单的对此进行了设计,如图所示 :

试着编译运行~~~~~~~~~

 可惜出错了,错误如下我的错误如下:

以下是我的解决方法:

 关于Qt创建的cmake工程加入QQuickWidget之后报错-CSDN博客

我们接着试着运行:

成功了!但是没有任何信息。我们接着添加。 

三、引入FluentUI组件库

  • 首先我们将FluentUI的源代码复制到自己的项目中来 

  • 我们在Qt Creator中添加它

 

 点击构建~~~~~~

又出错了

报错如上图,提示说是因为有个后缀为qm的文件被一个cpp文件需要,我们试着找到该目录,并没有该文件,我们从FluentUI中找出该文件 

将该文件移动到需要的路径下,也就是上述前面提示的位置,移动后的信息如下:

我们试着继续运行~~~~~~

又双叒出错了!!!

四、修改CMakeLists.txt文件

我们需要对顶层cmake文件进行设置,在如下位置添加信息:

  1. target_compile_definitions(ZWXM
  2. PRIVATE
  3. #导入qrcode配置文件
  4. HAVE_CONFIG_H
  5. )

我们继续运行~~~~~~

 运行成功!

五、创建我们自己的qml文件

前面我们已经将工程引入到了我们的工程中,现在我们创建qml文件引用它

添加以及创建过程可以参考网上教程:

通俗易懂玩QT:QQuickWidget学习-CSDN博客

本人创建后的项目结构如下所示:

六、将qml文件引入到QQuickWidget控件中

在QQuickWidget中引用我们的qml

 

七、引用FluentUI库

上面我们的qml文件是空白的,所以我们程序启动后任然是空白的,下面我们需要编辑qml文件:

我的文件如下:

CodeExpander.qml文件内容:

  1. import QtQuick 2.15
  2. import FluentUI 1.0
  3. FluExpander{
  4. id:control
  5. property string code: ""
  6. headerText: qsTr("Source")
  7. contentHeight:content.height
  8. focus: false
  9. FluCopyableText{
  10. id:content
  11. width:parent.width
  12. text:highlightQmlCode(code)
  13. textFormat: FluMultilineTextBox.RichText
  14. padding: 10
  15. topPadding: 10
  16. leftPadding: 10
  17. rightPadding: 10
  18. bottomPadding: 10
  19. }
  20. FluIconButton{
  21. iconSource:FluentIcons.Copy
  22. anchors{
  23. right: parent.right
  24. top: parent.top
  25. rightMargin: 5
  26. topMargin: 5
  27. }
  28. onClicked:{
  29. FluTools.clipText(FluTools.html2PlantText(content.text))
  30. showSuccess(qsTr("The Copy is Successful"))
  31. }
  32. }
  33. function htmlEncode(e){
  34. var i,s;
  35. for(i in s={
  36. "&":/&/g,//""//":/"/g,"'":/'/g,
  37. "<":/</g,">":/>/g,"<br/>":/\n/g,
  38. " ":/ /g," ":/\t/g
  39. })e=e.replace(s[i],i);
  40. return e;
  41. }
  42. function highlightQmlCode(code) {
  43. var qmlKeywords = [
  44. "FluTextButton",
  45. "FluAppBar",
  46. "FluAutoSuggestBox",
  47. "FluBadge",
  48. "FluButton",
  49. "FluCalendarPicker",
  50. "FluCalendarView",
  51. "FluCarousel",
  52. "FluCheckBox",
  53. "FluColorPicker",
  54. "FluColorView",
  55. "FluComboBox",
  56. "FluContentDialog",
  57. "FluContentPage",
  58. "FluDatePicker",
  59. "FluDivider",
  60. "FluDropDownButton",
  61. "FluExpander",
  62. "FluFilledButton",
  63. "FluFlipView",
  64. "FluFocusRectangle",
  65. "FluIcon",
  66. "FluIconButton",
  67. "FluInfoBar",
  68. "FluMediaPlayer",
  69. "FluMenu",
  70. "FluMenuItem",
  71. "FluMultilineTextBox",
  72. "FluNavigationView",
  73. "FluObject",
  74. "FluPaneItem",
  75. "FluPaneItemExpander",
  76. "FluPaneItemHeader",
  77. "FluPaneItemSeparator",
  78. "FluPivot",
  79. "FluPivotItem",
  80. "FluProgressBar",
  81. "FluProgressRing",
  82. "FluRadioButton",
  83. "FluRectangle",
  84. "FluScrollablePage",
  85. "FluScrollBar",
  86. "FluShadow",
  87. "FluSlider",
  88. "FluTabView",
  89. "FluText",
  90. "FluTextArea",
  91. "FluTextBox",
  92. "FluTextBoxBackground",
  93. "FluTextBoxMenu",
  94. "FluTextButton",
  95. "FluTextFiled",
  96. "FluTimePicker",
  97. "FluToggleSwitch",
  98. "FluTooltip",
  99. "FluTreeView",
  100. "FluWindow",
  101. "FluWindowResize",
  102. "FluToggleButton",
  103. "FluTableView",
  104. "FluColors",
  105. "FluTheme",
  106. "FluStatusLayout",
  107. "FluRatingControl",
  108. "FluPasswordBox",
  109. "FluBreadcrumbBar",
  110. "FluCopyableText",
  111. "FluAcrylic",
  112. "FluRemoteLoader",
  113. "FluMenuBar",
  114. "FluPagination",
  115. "FluRadioButtons",
  116. "FluImage",
  117. "FluSpinBox",
  118. "FluWatermark",
  119. "FluTour",
  120. "FluQRCode",
  121. "FluTimeline",
  122. "FluChart",
  123. "FluRangeSlider",
  124. "FluStaggeredLayout",
  125. "FluProgressButton",
  126. "FluLoadingButton",
  127. "FluClip",
  128. "FluNetwork",
  129. "FluShortcutPicker",
  130. "FluWindowResultLauncher",
  131. "FluRouter",
  132. "FluGroupBox",
  133. "FluSheet",
  134. ];
  135. code = code.replace(/\n/g, "<br>");
  136. code = code.replace(/ /g, "&nbsp;");
  137. return code.replace(RegExp("\\b(" + qmlKeywords.join("|") + ")\\b", "g"), "<span style='color: #c23a80'>$1</span>");
  138. }
  139. }

 sideBarQml.qml文件如下:

  1. import QtQuick 2.15
  2. import QtQuick.Controls 2.15
  3. import QtQuick.Layouts 1.15
  4. import QtQuick.Window 2.15
  5. import FluentUI 1.0
  6. FluScrollablePage{
  7. title: qsTr("Expander")
  8. FluFrame{
  9. Layout.fillWidth: true
  10. height: layout_column.height+20
  11. padding: 10
  12. Column{
  13. id:layout_column
  14. spacing: 15
  15. anchors{
  16. top:parent.top
  17. left:parent.left
  18. }
  19. FluExpander{
  20. headerText: qsTr("Open a radio box")
  21. Layout.topMargin: 20
  22. Item{
  23. anchors.fill: parent
  24. FluRadioButtons{
  25. spacing: 8
  26. anchors{
  27. top: parent.top
  28. left: parent.left
  29. topMargin: 15
  30. leftMargin: 15
  31. }
  32. FluRadioButton{
  33. text:"Radio Button_1"
  34. }
  35. FluRadioButton{
  36. text:"Radio Button_2"
  37. }
  38. FluRadioButton{
  39. text:"Radio Button_3"
  40. }
  41. }
  42. }
  43. }
  44. FluExpander{
  45. Layout.topMargin: 20
  46. headerText: qsTr("Open a sliding text box")
  47. Item{
  48. anchors.fill: parent
  49. Flickable{
  50. id:scrollview
  51. width: parent.width
  52. height: parent.height
  53. contentWidth: width
  54. boundsBehavior: Flickable.StopAtBounds
  55. contentHeight: text_info.height
  56. ScrollBar.vertical: FluScrollBar {}
  57. FluText{
  58. id:text_info
  59. width: scrollview.width
  60. wrapMode: Text.WrapAnywhere
  61. padding: 14
  62. text: qsTr("Permit me to observe: the late emperor was taken from us before he could finish his life`s work, the restoration of Han. Today, the empire is still divided in three, and our very survival is threatened. Yet still the officials at court and the soldiers throughout the realm remain loyal to you, your majesty. Because they remember the late emperor, all of them, and they wish to repay his kindness in service to you. This is the moment to extend your divine influence, to honour the memory of the late Emperor and strengthen the morale of your officers. It is not time to listen to bad advice, or close your ears to the suggestions of loyal men.
  63. The court and the administration are as one. Both must be judged by one standard. Those who are loyal and good must get what they deserve, but so must the evil-doers who break the law. This will demonstrate the justice of your rule. There cannot be one law for the court and another for the administration.
  64. Counselors and attendants like Guo Youzhi, Fei Yi, and Dong Yun are all reliable men, loyal of purpose and pure in motive. The late Emperor selected them for office so that they would serve you after his death.These are the men who should be consulted on all palace affairs. Xiang Chong has proved himself a fine general in battle, and the late Emperor believed in him. That is why the assembly has recommended him for overall command. It will keep the troops happy if he is consulted on all military matters.
  65. Xiang Chong has proved himself a fine general in battle, and the late Emperor believed in him. That is why the assembly has recommended him for overall command. It will keep the troops happy if he is consulted on all military matters.
  66. The emperors of the Western Han chose their courtiers wisely, and their dynasty flourished. The emperors of the Eastern Han chose poorly, and they doomed the empire to ruin. Whenever the late Emperor discussed this problem with me, he lamented the failings of Emperors Huan and Ling. Advisors like Guo Youzhi, Fei Yi, Chen Zhen, Zhang Yi, and Jiang Wan – these are all men of great integrity and devotion. I encourage you to trust them, your majesty, if the house of Han is to rise again.
  67. I begin as a common man, farming in my fields in Nanyang, doing what I could to survive in an age of chaos. I never had any interest in making a name for myself as a noble. The late Emperor was not ashamed to visit my cottage and seek my advice. Grateful for his regard, I responded to his appeal and threw myself into his service. Now twenty-one years has passed, the late Emperor always appreciated my caution and, in his final days, entrusted me with his cause.
  68. Since that moment, I have been tormented day and night by the fear that I might let him down. That is why I crossed the Lu river at the height of summer, and entered the wastelands beyond. Now the south has been subdued, and our forces are fully armed.I should lead our soldiers to conquer the northern heartland and attempt to remove the hateful traitors, restore the house of Han, and return it to the former capital.This the way I mean to honor my debt to the late Emperor and fulfill my duty to you. Guo Youzhi, Fei Yi, and Dong Yun are the ones who should be making policy decisions and recommendations.
  69. My only desire is to be permitted to drive out the traitors and restore the Han. If I should let you down, punish my offense and report it to the spirit of the late Emperor. If those three advisors should fail in their duties, then they should be punished for their negligence.Your Majesty, consider your course of action carefully. Seek out good advice, and never forget the late Emperor. I depart now on a long expedition, and I will be forever grateful if you heed my advice. Blinded by my own tears, I know not what I write.")
  70. }
  71. }
  72. }
  73. }
  74. }
  75. }
  76. CodeExpander{
  77. Layout.fillWidth: true
  78. Layout.topMargin: -6
  79. code:'FluExpander{
  80. headerText: qsTr("Open a radio box")
  81. Item{
  82. anchors.fill: parent
  83. Flickable{
  84. width: parent.width
  85. height: parent.height
  86. contentWidth: width
  87. contentHeight: text_info.height
  88. ScrollBar.vertical: FluScrollBar {}
  89. FluText{
  90. id:text_info
  91. width: scrollview.width
  92. wrapMode: Text.WrapAnywhere
  93. padding: 14
  94. text: qsTr("Permit me to observe: the late emperor was taken from us before he could finish his life`s work...")
  95. }
  96. }
  97. }
  98. }'
  99. }
  100. }

八、运行我们的程序

后续工作

qml的交互设计

声明:本文内容由网友自发贡献,不代表【wpsshop博客】立场,版权归原作者所有,本站不承担相应法律责任。如您发现有侵权的内容,请联系我们。转载请注明出处:https://www.wpsshop.cn/w/喵喵爱编程/article/detail/793420
推荐阅读
  

闽ICP备14008679号