小编Ste*_*TJS的帖子

QML ComboBox 样式

我使用以下代码自定义了一个组合框,但有些事情我不明白,因此无法修复。首先,悬停元素的高度,id 为 rectDlgt。我在控制台中输出 itemDlgt 和 rectDlgt 的高度,它们并不相同,而我期望它们应该相同。itemDlgt 的高度为 40,rectDlgt 的高度为 16。

第二件事是当我按下列表中的元素时出现的灰色矩形。我假设它链接到 listView,但即使在 ListView 中使用委托,它似乎也没有改变。

ComboBox {
  id:equipmentList
  anchors.verticalCenter: parent.verticalCenter
  width: 318
  height:64

  model: [ qsTr("Equipment1"), qsTr("Equipment2"), qsTr("Equipment3"), qsTr("Equipment4"), qsTr("Equipment5"), qsTr("Equipment6") ]

  //the background of the combobox
  background: Rectangle {
      color: "#95A4A8"
      border.color: "white"
      radius: height/2
  }

  delegate: ItemDelegate {
      id:itemDlgt
      width: equipmentList.width
      height:40

      contentItem: Rectangle{
          id:rectDlgt
          width:parent.implicitWidth
          height:itemDlgt.height
          color:itemDlgt.hovered?"#507BF6":"white";

          Text {
              id:textItem
              text: modelData
              color: hovered?"white":"#507BF6"
              font: equipmentList.font
              elide: Text.ElideRight
              verticalAlignment: Text.AlignVCenter
              horizontalAlignment: Text.AlignLeft
          }
       }

        onPressed: console.log(itemDlgt.height+" "+rectDlgt.height)//are …
Run Code Online (Sandbox Code Playgroud)

qt combobox styles qml qtquickcontrols2

6
推荐指数
1
解决办法
8956
查看次数

QML 获取加载的 qml 窗口的 winId

我想获取 qml 窗口的 winId。我有以下文件。

主.qml :

import QtQuick 2.5
import QtQuick.Window 2.2
import QtQuick.Controls 1.4

Window {
    id: myMainWindow
    title: "MyMainWindow"

    width: 200
    height: 200;
    visible: true

    Component.onCompleted: {
        x = 40
        y = 40
    }
}
Run Code Online (Sandbox Code Playgroud)

和我的 main.cpp :

#include <QGuiApplication>
#include <QQmlApplicationEngine>
#include <QWindow>

int main(int argc, char *argv[])
{
    QGuiApplication app(argc, argv);

    QQmlApplicationEngine engine;
    qmlRegisterType<FbItem>("fbitem", 1, 0, "FbItem");
    engine.load(QUrl(QStringLiteral("qrc:/main.qml")));

    QObject* m_rootObject = engine.rootObjects().first();
    auto rect_area = m_rootObject->findChild<QWindow*>("myMainWindow"); //the id of the Window in qml

    //both lines make …
Run Code Online (Sandbox Code Playgroud)

window hwnd qml

3
推荐指数
1
解决办法
2588
查看次数

如何将QDesktopServices :: openUrl与包含'#'的'file:'URL一起使用?

在我的应用程序中,我生成一个HTML文件,我想通过单击按钮打开它.所以我的文件被命名,例如:

QString file = "F:/the_path/to_the_/generated_html_file.html";
Run Code Online (Sandbox Code Playgroud)

在Windows上我将其更改为:

file = "file:///F:/the_path/to_the_/generated_html_file.html";
Run Code Online (Sandbox Code Playgroud)

所以我可以打开它:

QDesktopServices::openUrl(QUrl(file));
Run Code Online (Sandbox Code Playgroud)

它将在默认浏览器中打开.

但是当字符#存在于路径或文件名中时,它不再起作用,并且似乎URL在之后被截断#.

例如,如果我命名该文件generated#_html_file.html,我收到此错误消息:

ShellExecute 'F:/the_path/to_the_/generated' failed (error 2).
Run Code Online (Sandbox Code Playgroud)

为什么会发生这种情况,我该如何避免呢?

qt qurl qdesktopservices

2
推荐指数
2
解决办法
5376
查看次数

标签 统计

qml ×2

qt ×2

combobox ×1

hwnd ×1

qdesktopservices ×1

qtquickcontrols2 ×1

qurl ×1

styles ×1

window ×1