AskOverflow.Dev

AskOverflow.Dev Logo AskOverflow.Dev Logo

AskOverflow.Dev Navigation

  • 主页
  • 系统&网络
  • Ubuntu
  • Unix
  • DBA
  • Computer
  • Coding
  • LangChain

Mobile menu

Close
  • 主页
  • 系统&网络
    • 最新
    • 热门
    • 标签
  • Ubuntu
    • 最新
    • 热门
    • 标签
  • Unix
    • 最新
    • 标签
  • DBA
    • 最新
    • 标签
  • Computer
    • 最新
    • 标签
  • Coding
    • 最新
    • 标签
主页 / coding / 问题

问题[qt](coding)

Martin Hope
cancech
Asked: 2025-02-08 00:32:06 +0800 CST

如果存在 Q_OBJECT,则 Doxygen 更新类详细描述

  • 6

假设我有以下课程

/**
 * @brief Brief description
 *
 * Longer description
 */
class MyClass: public QObject {

    Q_OBJECT

public:
    /**
     * @brief CTOR
     */
    MyClass() = default;

    /**
     * @brief DTOR
     */
    virtual ~MyClass() = default;

   // Etcetera
};

当我去生成 Doxygen 文档时,会生成相应的文档,但是Q_OBJECT默认情况下它会忽略。我想要实现的是在生成的文档中向类添加某种指示,以表明该类支持Qt Signals and Slots。我可以使用该PREDEFINED属性让 Doxygen 用其他东西替换该宏

PREDEFINED = "Q_OBJECT=/// @note Supports Signals and Slots"

然而,这会应用于下一个后续元素(本例中为构造函数),而不是类本身。在我挖掘的过程中,我遇到了<运算符,但它似乎只适用于字段和参数,而不适用于类。

是否有某种方法可以在类文档中获得某种指示/标记来表明Q_OBJECT存在并且信号和槽将受到支持,而不依赖于手动将这样的标记添加到类注释中?

注意:我使用的是 Doxygen 版本 1.11.0

qt
  • 1 个回答
  • 23 Views
Martin Hope
julian
Asked: 2024-12-07 04:36:08 +0800 CST

放大 QGraphicsView 时 PySide6 中的 AnchorUnderMouse 出现问题(可能有错误?)

  • 7

我想放大 QGraphicsView,以便鼠标下的场景位置保持在鼠标下。以下代码实现了这一点:

from PySide6.QtCore import QPoint
from PySide6.QtWidgets import QGraphicsView, QGraphicsScene, QApplication
import math

class MyGraphicsView(QGraphicsView):
    def wheelEvent(self, event):
        self.setTransformationAnchor(self.ViewportAnchor.AnchorUnderMouse)
        self.setResizeAnchor(self.ViewportAnchor.AnchorUnderMouse)
        if event.angleDelta().y() > 0:
            self.scale(1.1, 1.1)
        elif event.angleDelta().y() < 0:
            self.scale(1 / 1.1, 1 / 1.1)
        self.setTransformationAnchor(self.ViewportAnchor.NoAnchor)
        self.setResizeAnchor(self.ViewportAnchor.NoAnchor)


class MyTestScene(QGraphicsScene):
    def drawBackground(self, painter, rect, PySide6_QtCore_QRectF=None, PySide6_QtCore_QRect=None):
        left = int(math.floor(rect.left()))
        top = int(math.floor(rect.top()))
        right = int(math.ceil(rect.right()))
        bottom = int(math.ceil(rect.bottom()))
        first_left = left - (left % 100)
        first_top = top - (top % 100)

        for x in range(first_left, right + 1, 100):
            for y in range(first_top, bottom + 1, 100):
                painter.drawEllipse(QPoint(x, y), 2.5, 2.5)
                painter.drawText(x, y, f"{x},{y}")


if __name__ == '__main__':
    app = QApplication([])
    scene = MyTestScene()
    scene.setSceneRect(-2000, -2000, 4000, 4000)
    view = MyGraphicsView()
    view.setScene(scene)
    view.setGeometry(100, 100, 900, 600)
    view.setVisible(True)
    # view.setInteractive(False)
    app.exec()

此代码存在以下问题:

  • 如果用户在第一次尝试使用滚轮缩放之前单击了视图(并且该视图是“交互式的”),则一切都会按预期工作。
  • 如果不是,在第一个滚轮事件中,场景会“跳跃”(除了正确缩放之外,还会平移),以便 (0, 0) 位于鼠标下方。此后,一切都按预期运行。
  • 如果视图设置为“非交互式”,场景就会“跳跃”,使得每次滚轮事件发生时 (0, 0) 都位于鼠标下方。

有人能解释一下这种行为吗?我遗漏了什么吗?或者这是 Qt 中的一个错误?

我尝试在 python 3.12.4 下使用 PySide 6.7.2,并在 python 3.13.1 下使用 PySide 6.8.1(均在 Windows 上),结果相同。

qt
  • 1 个回答
  • 20 Views
Martin Hope
vincent
Asked: 2024-11-28 20:01:37 +0800 CST

使用 QPainter 的 drawPixmap/drawImage 绘制图像,图像看起来很模糊

  • 6

我使用QPainterdrawPixmap() 绘制了一幅图像,结果如下图B所示。

然后,我在 Windows 提供的图像查看器程序中打开同一张图片,并将其放大得更小,如下图A所示。

drawPixmap.jpeg 明显B比A大,但是没有A清晰,B有明显的混叠。

我尝试了setRenderHint(QPainter::Antialiasing)一下setRenderHint(QPainter::SmoothPixmapTransform),有一定的效果,但不足以解决问题。

我尝试了不同的方式来显示同一幅图像(OpenGL、webEngine、QPainter.drawPixmap、graphicsView),结果各不相同,但它们的质量都低于 Windows 内置图像查看器。

QOpenGLWidget.png

我不认为这是图像清晰度的问题。当我使用 drawPixmap() 绘制图像并调用 QPainter 的 scale() 方法将其放大时,我可以看到图像的细节。

有人知道如何在 Qt 中绘制与内置 Windows 软件清晰度相同的图像吗?即使我缩小图像,我也想避免混叠问题。

- 编辑 -

最小可重现演示:

// canvaswidget.h
#ifndef CANVASWIDGET_H
#define CANVASWIDGET_H

#include <QWidget>

class CanvasWidget : public QWidget
{
    Q_OBJECT
public:
    explicit CanvasWidget(QImage img, QWidget *parent = nullptr);
    void zoomIn();
    void zoomOut();

signals:

protected:
    QSize sizeHint();
    void paintEvent(QPaintEvent *event) override;
    void wheelEvent(QWheelEvent *event) override;

private:
    qreal scale;
    QPixmap pixmap;
};

#endif // CANVASWIDGET_H
// canvaswidget.cpp
#include "canvaswidget.h"
#include <QWheelEvent>
#include <QPainter>
#include <QPixmap>

CanvasWidget::CanvasWidget(QImage img, QWidget *parent)
    : QWidget{parent}, scale(1.0)
{
    // make sure high resolution source
    pixmap = QPixmap::fromImage(img.scaled(img.size() * 10, Qt::KeepAspectRatio, Qt::SmoothTransformation));
}

void CanvasWidget::zoomIn() {
    scale = fmin(scale + 0.1, 10);
    update();
}

void CanvasWidget::zoomOut() {
    scale = fmax(scale - 0.1, 0.1);
    update();
}

void CanvasWidget::paintEvent(QPaintEvent *event) {
    if(!pixmap) {
        return QWidget::paintEvent(event);
    }
    QPainter p(this);

    p.setRenderHint(QPainter::Antialiasing);
    p.setRenderHint(QPainter::SmoothPixmapTransform);
    p.drawPixmap(0,0,width() * scale,height() * scale, pixmap); // draw image
}

void CanvasWidget::wheelEvent(QWheelEvent *event)
{

    if(event->modifiers() == Qt::ControlModifier) {
        QPointF delta = event->angleDelta();
        int v_delta = delta.y();
        if(v_delta > 0) {
            zoomIn();
        } else {
            zoomOut();
        }
        update();
        adjustSize();
    } else {
        QWidget::wheelEvent(event);
    }
}
QSize CanvasWidget::sizeHint()
{
    return QSize(800,800);
}

下图左侧为本次演示的结果,右侧为Windows内置的图像查看器。

在此处输入图片描述

--- 编辑 2 ---

这是我在演示中使用的图像,它的格式是 PNG QImage::Format_ARGB32,大小是QSize(1541, 1188) 25KB 在此处输入图片描述

qt
  • 2 个回答
  • 74 Views
Martin Hope
Dante
Asked: 2024-11-27 23:56:23 +0800 CST

QPdfView 中的可滚动覆盖

  • 6

我正在 QPdfView 中显示 pdf 文档,并且需要在几页上的某些区域上绘制覆盖层。

我已经设法绘制了覆盖层,但我需要一些帮助来调整滚动时其位置的调整方式。

代码如下:

from PySide6.QtCore import QRectF
from PySide6.QtGui import QPainter, QColor
from PySide6.QtPdfWidgets import QPdfView
from PySide6.QtCore import Qt
from PySide6.QtPdf import QPdfDocument

class CustomPdfView(QPdfView):  
    def __init__(self, parent=None):
        super().__init__(parent)
        
        # Placeholder areas
        self.highlights: dict[int, list[QRectF]] = {
            i : [QRectF(150.0, 150.0, 300.0, 300.0)] for i in range(200)
            }

    def paintEvent(self, event):
        super().paintEvent(event)

        if self.document().status() == QPdfDocument.Status.Ready:

            current_page_number = self.pageNavigator().currentPage()

            if current_page_number in self.highlights.keys():
                painter = QPainter(self.viewport())
                painter.setRenderHint(QPainter.RenderHint.Antialiasing)
                painter.setBrush(QColor(255, 255, 0, 100))
                painter.setPen(Qt.PenStyle.NoPen)

                total_pages = self.document().pageCount()
                current_page_size = self.document().pagePointSize(current_page_number)
                viewport_size = self.viewport().size()
                
                scroll_bar = self.verticalScrollBar()
                max_scroll = scroll_bar.maximum()
                
                scroll_per_page = max_scroll / total_pages
                scroll_calculated = scroll_per_page * current_page_number
                
                for rect in self.highlights[current_page_number]:

                    h_diff = scroll_bar.value() - scroll_calculated
                    
                    scaled_rect = QRectF(
                        (rect.x() / current_page_size.width()) * viewport_size.width(),
                        rect.y() - h_diff,
                        (rect.width() / current_page_size.width()) * viewport_size.width(),
                        rect.height()
                    )
                    painter.drawRect(scaled_rect)

                painter.end()

在最好的情况下,我想知道当前页面在视口中呈现了多少像素,因此 h_diff 变为 page_height - 可见像素

qt
  • 1 个回答
  • 31 Views
Martin Hope
Henry Gomersall
Asked: 2024-07-05 23:20:14 +0800 CST

如何缩放 QML 矩形而不缩放任何子文本

  • 5

我有下面列出的 QML 组件。我遇到的问题是,当我使用捏合区域缩放矩形时(我希望发生这种情况),该矩形的子文本也会被缩放(我不希望发生这种情况)。

是什么导致文本缩放?鉴于Text的scale属性已明确设置为1.0以及font.pointSize,我完全不明白文本为何会发生变化。

如何创建可扩展组件的文本,而文本本身不进行缩放?

QML代码:

import QtQuick 2

Rectangle {
    id: page
    width: 1000; height: 1000
    color: "black"

    Rectangle {
        id: image_boundary
        color: "green"
        width: 200
        height: 100
        x: (parent.width/2)-(image_boundary.width/2)
        y: (parent.height/2)-(image_boundary.height/2)

        onScaleChanged: {
            console.log("Scale changed:", scale)
        }

        PinchArea {
            anchors.fill: image_boundary
            property real initialScale: 1.0
            property real scale: 1.0
            id: pinch_area

            onPinchStarted: {
                initialScale = scale
            }

            onPinchUpdated: function(pinch) {
                scale = initialScale * pinch.scale
                console.log(scale)
                parent.scale = scale
            }
        }
        Text {
            text: "mumble mumble"
            font.pointSize: 10
            scale: 1.0
            color: "yellow"
            anchors.left: parent.right
        }
    }
}

我可以使用以下 Python 代码(使用 PySide6)运行它:

import sys
from pathlib import Path
from PySide6.QtQuick import QQuickView
from PySide6.QtCore import QUrl
from PySide6.QtGui import QGuiApplication


if __name__ == '__main__':

    #Set up the application window
    app = QGuiApplication(sys.argv)
    view = QQuickView()
    view.setResizeMode(QQuickView.SizeRootObjectToView)

    #Load the QML file
    qml_file = Path(__file__).parent / "test_qml_file.qml"
    view.setSource(QUrl.fromLocalFile(qml_file.resolve()))

    #Show the window
    if view.status() == QQuickView.Error:
        sys.exit(-1)
    view.show()

    #execute and cleanup
    app.exec()
    del view
qt
  • 1 个回答
  • 20 Views
Martin Hope
Marco81
Asked: 2024-06-10 06:38:14 +0800 CST

复制 QByteArray 时出现意外行为

  • 5

我正在研究解码类似 HDLC 的协议,并从网上找到的一些代码开始(https://github.com/jarkko-hautakorpi/Arduhdlc)。以下代码是摘录,重点介绍我遇到的问题。它读取 QByteArray(来自串行),然后丢弃初始和最终帧边界字节,管理转义序列并检查 CRC

#include <QCoreApplication>
#include <QDebug>
#include "hdlc_qt.h"

#define FRAME_BOUNDARY_OCTET 0x7E
#define CONTROL_ESCAPE_OCTET 0x7D
#define INVERT_OCTET 0x20
QByteArray receive_frame_buffer;
quint16 frame_position;
quint16 frame_checksum;
bool escape_character;


bool hdlcFrameCRC_check(int frame_index);

void charReceiver(QByteArray dataArray)
{

    quint8 data = 0;
    qDebug() << "Received:\t"<<dataArray.toHex();
    for(QByteArray::iterator it = dataArray.begin(); it != dataArray.end(); it++) {
        data = (*it);
        //qDebug ("data: %x",data);
        /* Start flag or end flag */
        if(data == FRAME_BOUNDARY_OCTET) {

            qDebug("FRAME_BOUNDARY_OCTET: %x",data);
            qDebug() << "frame_position:"<<frame_position;
            if(escape_character == true) {
                escape_character = false;
            }
            /* Do CRC check if frame is valid */

            else if(  (frame_position >= 2) && (hdlcFrameCRC_check(frame_position)) )  {
                /* Call user defined function to handle HDLC frame */
                qDebug() << "ValidFrame"<<receive_frame_buffer.toHex();

            }
            qDebug() << "frame_buffer:\t"<<receive_frame_buffer.toHex();
            /* Reset all for next frame */
            frame_position = 0;
            frame_checksum = 0;
            receive_frame_buffer.clear();
            continue;

        }

        if(escape_character) {
            escape_character = false;
            data ^= INVERT_OCTET;
        } else if(data == CONTROL_ESCAPE_OCTET) {
            escape_character = true;
            continue;
        }
        //receive_frame_buffer[frame_position] = data;
        receive_frame_buffer.append(data); //changed to avoid compiler warning

        // qDebug ("rx_framebuf[%d] = %x",frame_position,receive_frame_buffer.at(frame_position));

        frame_position++;

        /* If we don't ever receive valid frame,
         * buffer will keep growing bigger and bigger.
         * Hard coded max size limit and then reset
         */
        if(frame_position >= 2048)
        {
            receive_frame_buffer.clear();
            frame_position = 0;
            frame_checksum = 0;
        }
    }
}

bool hdlcFrameCRC_check(int frame_index)
{
    /* frame = ...[CRC-LO] [CRC-HI] */
    quint16 crc_received = 0;
    crc_received = receive_frame_buffer[frame_index-1]; // msb
    crc_received = crc_received << 8;
    crc_received |= receive_frame_buffer[frame_index-2]; // lsb
    quint16 crc_calculated = qChecksum((const char*)receive_frame_buffer.constData(), frame_index-2);
    //crc_calculated = crc_calculated^0xFFFF;

    qDebug("CRC received:%x",crc_received);
    qDebug("CRC calculated:%x",crc_calculated);

    if(crc_received == crc_calculated) {
        return true;
    } else {
        return false;
    }
}

int main(int argc, char *argv[])
{
    QCoreApplication a(argc, argv);


    QByteArray test1 = QByteArray("\x7E\x08\x1A\x00\x00\x07\x2B\x08\x00\x08\x16\x00\x00\x08\x8E\x07\xF7\x22\x20\x7E",20);
    QByteArray test2 = QByteArray("\x7e\x08\x22\x00\x00\x07\x28\x08\x08\x08\x10\x00\x05\x08\x95\x07\xff\xf6\x41\x7e",20);
    QByteArray test3 = QByteArray("\x7e\x08\x22\x00\x00\x07\x21\x08\x09\x08\x10\x00\x07\x08\x8f\x08\x00\xe7\x89\x7e",20);
    QByteArray test4 = QByteArray("\x7e\x08\x0e\x00\x00\x07\x2f\x08\x07\x08\x1b\x00\x00\x08\x93\x07\xf8\x9a\xb1\x7e",20);
    QByteArray test5 = QByteArray("\x7e\x08\x27\x00\x00\x07\x27\x08\x0a\x08\x10\x00\x05\x08\x93\x07\xfd\x18\x53\x7e",20);

    QVector<QByteArray> test;
    test.push_back(test1);
    test.push_back(test2);
    test.push_back(test3);
    test.push_back(test4);
    test.push_back(test5);

    for(int i = 0; i < test.size();++i) {
        qDebug()<<"-------------------------------------------------------";
        qDebug()<<"Test #" << i+1<< ":\t "<< test[i].toHex();
        charReceiver(test[i]);

    }
    return a.exec();
}

我准备了一些测试,分别命名为 test1、...、test5,并发现它在 CRC 验证步骤中失败。问题是,在某些测试中,传递给方法的 CRC 序列是初始序列中不存在的序列。对于 test1,CRC 序列(“\x22\x20”)正确传递,而在 test2 中,方法接收的是“\xff\xf6”,而不是“\xf6\x41”,对于 test3 和 test4 也是如此,而 test5 是正确的。您有什么可能的解释和补救措施吗?

qt
  • 1 个回答
  • 30 Views
Martin Hope
Damn Vegetables
Asked: 2024-04-23 21:30:09 +0800 CST

为什么 QTreeView 不将新添加的节点显示到 QAbstractItemModel 中的非根节点

  • 6

我为 QTreeView 创建了一个自定义模型。显示问题的完整最小代码如下。如果我向根节点添加一个新节点,通过单击“添加级别 1”,它就会显示。但是,如果我通过单击“添加级别 2”将新节点添加到第二级别,则它不会显示。仅当我折叠父节点然后再次展开它时,该节点才会显示。我的哪一部分MyTreeModel出了问题?

在此输入图像描述

我添加了 QT 标签,即使我的代码是 PySide6,因为错误可能在于我对 QAbstractItemModel 方法的理解,这不是 Python 或 PySide 特有的东西。

完整代码

from __future__ import annotations
from typing import Optional

from PySide6.QtCore import QAbstractItemModel, QModelIndex
from PySide6.QtGui import Qt
from PySide6.QtWidgets import QApplication, QMainWindow, QWidget, QVBoxLayout, QPushButton, QHBoxLayout, QTreeView


class TreeNode:
    def __init__(self, name: str, parent_node):
        self.name = name
        self.parent_node = parent_node
        self.children: list[TreeNode] = []

    def get_child_by_name(self, name) -> Optional[TreeNode]:
        for child in self.children:
            if child.name == name:
                return child

        return None


class MyTreeModel(QAbstractItemModel):
    def __init__(self):
        super().__init__()
        self.root_node = TreeNode("root", None)

    def headerData(self, section, orientation, role=Qt.DisplayRole):
        if orientation == Qt.Horizontal and role == Qt.DisplayRole:
            return "Name"

    def rowCount(self, parentIndex):
        if not parentIndex.isValid():
            parentNode = self.root_node
        else:
            parentNode = parentIndex.internalPointer()

        return len(parentNode.children)

    def columnCount(self, parent):
        return 1

    def data(self, index, role):
        if not index.isValid():
            return None

        if role == Qt.DisplayRole:
            node: TreeNode = index.internalPointer()
            column = index.column()
            match column:
                case 0:
                    return node.name
                case _:
                    return None
        else:
            return None

    def parent(self, index):
        if not index.isValid():
            return QModelIndex()

        childNode: TreeNode = index.internalPointer()
        parentNode = childNode.parent_node

        if parentNode == self.root_node:
            return QModelIndex()

        row_within_parent = parentNode.children.index(childNode)

        return self.createIndex(row_within_parent, 0, parentNode);

    def index(self, row, column, parentIndex):
        if not self.hasIndex(row, column, parentIndex):
            return QModelIndex()

        if not parentIndex.isValid():
            parentNode = self.root_node
        else:
            parentNode = parentIndex.internalPointer()

        child_node = parentNode.children[row]
        if child_node:
            return self.createIndex(row, column, child_node)
        else:
            return QModelIndex()

    def set_data(self, data: []):
        self.beginResetModel()
        self.apply_data(data)
        self.endResetModel()

    def update_data(self, data: []):
        self.apply_data(data, True)

    def apply_data(self, data, notify=False):
        for item in data:
            parent_node = self.root_node;
            for part in item.split("/"):
                existing = parent_node.get_child_by_name(part)
                if existing:
                    parent_node = existing
                else:
                    if notify:
                        parent_index = self.get_index(parent_node)
                        count = len(parent_node.children)
                        self.beginInsertRows(parent_index, count, count)

                    new_node = TreeNode(part, parent_node)
                    parent_node.children.append(new_node)
                    parent_node = new_node

                    if notify:
                        self.endInsertRows()

    def get_index(self, node: TreeNode):
        if not node.parent_node:
            return QModelIndex()

        row = node.parent_node.children.index(node)
        return self.createIndex(row, 0, node.parent_node)


class MainWindow(QMainWindow):
    def __init__(self):
        super().__init__()
        self.resize(600, 400)

        button1 = QPushButton("Add Level 1")
        button1.clicked.connect(self.add1)
        button2 = QPushButton("Add Level 2")
        button2.clicked.connect(self.add2)

        row1 = QHBoxLayout()
        row1.setAlignment(Qt.AlignLeft)
        row1.addWidget(button1)
        row1.addWidget(button2)

        self.tree_view = QTreeView()

        layout = QVBoxLayout()
        layout.addLayout(row1)
        layout.addWidget(self.tree_view, stretch=1)

        self.central_widget = QWidget()
        self.central_widget.setLayout(layout)
        self.setCentralWidget(self.central_widget)

    def showEvent(self, event):
        data = ["mammals", "birds", "mammals/dog", "birds/eagle", "mammals/cat"]

        my_model = MyTreeModel()
        my_model.set_data(data)
        self.tree_view.setModel(my_model)
        self.tree_view.expandAll()

    def add1(self):
        data = ["reptiles"]
        m = self.tree_view.model()
        m.update_data(data)

    def add2(self):
        data = ["mammals/rat"]
        m = self.tree_view.model()
        m.update_data(data)


app = QApplication([])
win = MainWindow()
win.show()
app.exec()
qt
  • 1 个回答
  • 29 Views
Martin Hope
eepp
Asked: 2024-02-20 03:17:49 +0800 CST

如何让自定义QWidget接收所有按键事件,甚至全局操作的快捷方式?

  • 5

在 Qt 5 中,假设有以下自定义小部件:

class QMeow final :
    public QWidget
{
public:
    explicit QMeow()
    {
        this->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Expanding);
        this->setFocusPolicy(Qt::StrongFocus);
    }

protected:
    void keyPressEvent(QKeyEvent * const event) override
    {
        _s = !_s;
        this->update();
        QWidget::keyPressEvent(event);
    }

    void paintEvent(QPaintEvent *) override
    {
        QPainter painter {this};

        painter.fillRect(this->rect(), QColor {_s ? "red" : "blue"});
    }

private:
    bool _s = false;
};

当按下任意键时,此小部件的实例会在红色和蓝色之间更改其背景颜色。

现在,让我们创建一个窗口并添加 aQLineEdit和 a ,并使用快捷键AQMeow设置操作:

QApplication app {argc, argv};
QWidget window;
QVBoxLayout layout {&window};

layout.addWidget(new QLineEdit);
layout.addWidget(new QMeow);

QAction action {"hello"};

action.setShortcut(Qt::Key_A);
window.addAction(&action);

window.show();
app.exec();

如果您尝试这样做,您会注意到:

  • 当QLineEdit小部件获得焦点时,它会处理所有键,包括小写A,并将其添加到渲染的文本中。
  • 当QMeow小部件获得焦点时,它会处理除小写A之外的所有键,这表明操作会处理它。

如何QMeow::keyPressEvent()调用任何键,包括操作快捷键,例如QLineEdit?

我尝试了QWidget::grabKeyboard()不同的焦点策略,但qlineedit.cpp没有成功。

qt
  • 1 个回答
  • 27 Views
Martin Hope
Alexy Ibrahim
Asked: 2024-02-17 19:22:20 +0800 CST

Qt Creator 构建失败 - 无法克隆新 Qt Quick 应用程序的存储库

  • 5

我正在尝试在 Qt Creator 中创建一个新的 Qt Quick 应用程序。然而,每次我尝试构建该项目时,它甚至在执行任何操作之前都会立即失败。

/PATH/QMLTest/ds-subbuild/ds-populate-prefix/tmp/ds-populate-gitclone.cmake:39: error: Failed to clone repository:  
'https://code.qt.io/qt-labs/qtquickdesigner-components.git'  
:-1: error: ninja: build stopped: subcommand failed.  
/PATH/QMLTest/CMakeLists.txt:32: error: Build step for ds failed: 1

Call stack:  
  /PATH/QMLTest/CMakeLists.txt:32 (include)  
  /PATH/QMLTest/qmlcomponents:16 (FetchContent_Populate)  
  /opt/homebrew/Cellar/cmake/3.28.3/share/cmake/Modules/FetchContent.cmake:1819 (cmake_language)  
  /opt/homebrew/Cellar/cmake/3.28.3/share/cmake/Modules/FetchContent.cmake:1819:EVAL:2 (__FetchContent_directPopulate)  
  /opt/homebrew/Cellar/cmake/3.28.3/share/cmake/Modules/FetchContent.cmake:1679 (message)  
:-1: error: CMake process exited with exit code 1.  
:-1: error: CMake project configuration failed. No CMake configuration for build type "Debug" found.

克隆存储库似乎存在一些问题https://code.qt.io/qt-labs/qtquickdesigner-components.git,我什至无法使用浏览器访问它。我不知道该怎么做才能解决这个问题。如果您需要更多信息,请告诉我。

这是终端构建输出:

$ cmake -S '/PATH/FirstQML' -B /PATH/Qt/Builds/build-FirstQML-Qt_6_6_1_for_macOS-Debug
-- The CXX compiler identification is AppleClang 15.0.0.15000100
-- Detecting CXX compiler ABI info
-- Detecting CXX compiler ABI info - done
-- Check for working CXX compiler: /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/clang++ - skipped
-- Detecting CXX compile features
-- Detecting CXX compile features - done
Building designer components.
[1/9] Creating directories for 'ds-populate'
[1/9] Performing download step (git clone) for 'ds-populate'
Cloning into 'ds-src'...
fatal: unable to access 'https://code.qt.io/qt-labs/qtquickdesigner-components.git/': Failed to connect to code.qt.io port 443 after 75 ms: Couldn't connect to server
Cloning into 'ds-src'...
fatal: unable to access 'https://code.qt.io/qt-labs/qtquickdesigner-components.git/': Failed to connect to code.qt.io port 443 after 74 ms: Couldn't connect to server
Cloning into 'ds-src'...
fatal: unable to access 'https://code.qt.io/qt-labs/qtquickdesigner-components.git/': Failed to connect to code.qt.io port 443 after 73 ms: Couldn't connect to server
-- Had to git clone more than once: 3 times.
CMake Error at ds-subbuild/ds-populate-prefix/tmp/ds-populate-gitclone.cmake:39 (message):
  Failed to clone repository:
  'https://code.qt.io/qt-labs/qtquickdesigner-components.git'


FAILED: ds-populate-prefix/src/ds-populate-stamp/ds-populate-download /PATH/Qt/Builds/build-FirstQML-Qt_6_6_1_for_macOS-Debug/_deps/ds-subbuild/ds-populate-prefix/src/ds-populate-stamp/ds-populate-download 
cd /PATH/Qt/Builds/build-FirstQML-Qt_6_6_1_for_macOS-Debug/_deps && /opt/homebrew/Cellar/cmake/3.28.3/bin/cmake -P /PATH/Qt/Builds/build-FirstQML-Qt_6_6_1_for_macOS-Debug/_deps/ds-subbuild/ds-populate-prefix/tmp/ds-populate-gitclone.cmake && /opt/homebrew/Cellar/cmake/3.28.3/bin/cmake -E touch /PATH/Qt/Builds/build-FirstQML-Qt_6_6_1_for_macOS-Debug/_deps/ds-subbuild/ds-populate-prefix/src/ds-populate-stamp/ds-populate-download
ninja: build stopped: subcommand failed.

CMake Error at /opt/homebrew/Cellar/cmake/3.28.3/share/cmake/Modules/FetchContent.cmake:1679 (message):
  Build step for ds failed: 1
Call Stack (most recent call first):
  /opt/homebrew/Cellar/cmake/3.28.3/share/cmake/Modules/FetchContent.cmake:1819:EVAL:2 (__FetchContent_directPopulate)
  /opt/homebrew/Cellar/cmake/3.28.3/share/cmake/Modules/FetchContent.cmake:1819 (cmake_language)
  qmlcomponents:16 (FetchContent_Populate)
  CMakeLists.txt:32 (include)


-- Configuring incomplete, errors occurred!

感谢任何有助于解决此问题的帮助或提示。提前致谢!

qt
  • 1 个回答
  • 43 Views
Martin Hope
Евгений Дружинин
Asked: 2024-01-09 22:06:02 +0800 CST

Qml 映射全局坐标不正确

  • 6

在此代码部分中,我创建了内部包含窗口和矩形的简单示例。我为矩形设置 x = 100 和 y = 100 内部坐标。当我将这些坐标映射到全局并得到不正确的结果时,坐标总是比实际坐标多 2 倍。例如,如果我将 x 和 y 设置为 50,则结果将为 50*2 = 100。为什么会出现错误?我该如何修复它?

    import QtQuick 2.15
    import QtQuick.Window 2.15
    
    Window {
        id: root
    
        width: 640; height: 480; visible: true;
        title: qsTr("Hello World")
        onXChanged: innerRect.globalChanged();
        onYChanged: innerRect.globalChanged()
        onWidthChanged: innerRect.globalChanged();
        onHeightChanged: innerRect.globalChanged()
    
        Rectangle {
            id: innerRect
    
            signal globalChanged()
            property point globalPoint
            onGlobalChanged: {
                innerRect.globalPoint = mapToGlobal(innerRect.x, innerRect.y)
            }
            color: "yellow"
            width: parent.width / 2; height: parent.height / 2
    
            x: 100; y: 100
    
            Text {
                id: xCoord
    
                anchors.left: parent.left;
                anchors.leftMargin: 20
                anchors.verticalCenter: parent.verticalCenter
                text: "Gx: " + innerRect.globalPoint.x + " Wx: " + root.x
            }
            Text {
                id: yCoord
    
                anchors.right: parent.right;
                anchors.rightMargin: 20
                anchors.verticalCenter: parent.verticalCenter
                text: "Gy: " + innerRect.globalPoint.y + " Wy: " + root.y
            }
        }
    }

在此输入图像描述

qt
  • 1 个回答
  • 20 Views

Sidebar

Stats

  • 问题 205573
  • 回答 270741
  • 最佳答案 135370
  • 用户 68524
  • 热门
  • 回答
  • Marko Smith

    重新格式化数字,在固定位置插入分隔符

    • 6 个回答
  • Marko Smith

    为什么 C++20 概念会导致循环约束错误,而老式的 SFINAE 不会?

    • 2 个回答
  • Marko Smith

    VScode 自动卸载扩展的问题(Material 主题)

    • 2 个回答
  • Marko Smith

    Vue 3:创建时出错“预期标识符但发现‘导入’”[重复]

    • 1 个回答
  • Marko Smith

    具有指定基础类型但没有枚举器的“枚举类”的用途是什么?

    • 1 个回答
  • Marko Smith

    如何修复未手动导入的模块的 MODULE_NOT_FOUND 错误?

    • 6 个回答
  • Marko Smith

    `(表达式,左值) = 右值` 在 C 或 C++ 中是有效的赋值吗?为什么有些编译器会接受/拒绝它?

    • 3 个回答
  • Marko Smith

    在 C++ 中,一个不执行任何操作的空程序需要 204KB 的堆,但在 C 中则不需要

    • 1 个回答
  • Marko Smith

    PowerBI 目前与 BigQuery 不兼容:Simba 驱动程序与 Windows 更新有关

    • 2 个回答
  • Marko Smith

    AdMob:MobileAds.initialize() - 对于某些设备,“java.lang.Integer 无法转换为 java.lang.String”

    • 1 个回答
  • Martin Hope
    Fantastic Mr Fox msvc std::vector 实现中仅不接受可复制类型 2025-04-23 06:40:49 +0800 CST
  • Martin Hope
    Howard Hinnant 使用 chrono 查找下一个工作日 2025-04-21 08:30:25 +0800 CST
  • Martin Hope
    Fedor 构造函数的成员初始化程序可以包含另一个成员的初始化吗? 2025-04-15 01:01:44 +0800 CST
  • Martin Hope
    Petr Filipský 为什么 C++20 概念会导致循环约束错误,而老式的 SFINAE 不会? 2025-03-23 21:39:40 +0800 CST
  • Martin Hope
    Catskul C++20 是否进行了更改,允许从已知绑定数组“type(&)[N]”转换为未知绑定数组“type(&)[]”? 2025-03-04 06:57:53 +0800 CST
  • Martin Hope
    Stefan Pochmann 为什么 {2,3,10} 和 {x,3,10} (x=2) 的顺序不同? 2025-01-13 23:24:07 +0800 CST
  • Martin Hope
    Chad Feller 在 5.2 版中,bash 条件语句中的 [[ .. ]] 中的分号现在是可选的吗? 2024-10-21 05:50:33 +0800 CST
  • Martin Hope
    Wrench 为什么双破折号 (--) 会导致此 MariaDB 子句评估为 true? 2024-05-05 13:37:20 +0800 CST
  • Martin Hope
    Waket Zheng 为什么 `dict(id=1, **{'id': 2})` 有时会引发 `KeyError: 'id'` 而不是 TypeError? 2024-05-04 14:19:19 +0800 CST
  • Martin Hope
    user924 AdMob:MobileAds.initialize() - 对于某些设备,“java.lang.Integer 无法转换为 java.lang.String” 2024-03-20 03:12:31 +0800 CST

热门标签

python javascript c++ c# java typescript sql reactjs html

Explore

  • 主页
  • 问题
    • 最新
    • 热门
  • 标签
  • 帮助

Footer

AskOverflow.Dev

关于我们

  • 关于我们
  • 联系我们

Legal Stuff

  • Privacy Policy

Language

  • Pt
  • Server
  • Unix

© 2023 AskOverflow.DEV All Rights Reserve