RError.com

RError.com Logo RError.com Logo

RError.com Navigation

  • 主页

Mobile menu

Close
  • 主页
  • 系统&网络
    • 热门问题
    • 最新问题
    • 标签
  • Ubuntu
    • 热门问题
    • 最新问题
    • 标签
  • 帮助
主页 / user-467525

ардуино IDE's questions

Martin Hope
ардуино IDE
Asked: 2022-07-18 18:41:57 +0000 UTC

QSizeGrip 无法正常工作

  • 1

我写了这段代码,但它不能正常工作(在我看来)。
如果您知道如何使其正常工作,请提供帮助。

拉伸就像Qt Dsigner的,但我不明白它是怎么发生的。

它应该像这样工作:

像 QtDsigner 一样伸展

from PyQt5 import QtCore, QtGui, QtWidgets


class SizeGrip(QtWidgets.QSizeGrip):
    def __init__(self, location_angle, parent):
        super().__init__(parent)

        parent.installEventFilter(self)
        self.setFixedSize(30, 30)
        self.location_angle = location_angle

    def eventFilter(self, source, event):
        if event.type() == QtCore.QEvent.Resize:
            if self.location_angle == 'left_top':
                geo = QtCore.QRect(0, 0, 30, 30)
                self.setGeometry(geo)
            elif self.location_angle == 'center_top':
                _geo = self.rect()
                _geo.moveBottomRight(source.rect().bottomRight())
                x = _geo.x() // 2
                geo = QtCore.QRect(x, 0, 30, 30)
                self.setGeometry(geo)
            elif self.location_angle == 'right_top':
                _geo = self.rect()
                _geo.moveBottomRight(source.rect().bottomRight())
                x = _geo.x()
                geo = QtCore.QRect(x, 0, 30, 30)
                self.setGeometry(geo)
            elif self.location_angle == 'left_bottom':
                _geo = self.rect()
                _geo.moveBottomRight(source.rect().bottomRight())
                y = _geo.y()
                geo = QtCore.QRect(0, y, 30, 30)
                self.setGeometry(geo)
            elif self.location_angle == 'right_bottom':
                geo = self.rect()
                geo.moveBottomRight(source.rect().bottomRight())
                self.setGeometry(geo)
        return super().eventFilter(source, event)

    def paintEvent(self, event):
        qp = QtGui.QPainter(self)
        qp.setPen(QtCore.Qt.white)
        qp.setBrush(QtCore.Qt.red)
        qp.drawRect(QtCore.QRect(10, 10, 10, 10))


class Container(QtWidgets.QWidget):
    def __init__(self, *args, **kwargs):
        super().__init__(*args, **kwargs)

        self.sizeGrip1 = SizeGrip('left_top', self)
        self.sizeGrip1_1 = SizeGrip('center_top', self)
        self.sizeGrip2 = SizeGrip('right_top', self)
        self.sizeGrip3 = SizeGrip('left_bottom', self)
        self.sizeGrip4 = SizeGrip('right_bottom', self)

        self.startPos = None
        layout = QtWidgets.QVBoxLayout(self)
        layout.setContentsMargins(20, 20, 20, 20)
        self.setStyleSheet('''
            Container {
                background: lightblue;
                border: 0px;
                border-radius: 4px;
            }
        ''')

    def mousePressEvent(self, event):
        if event.button() == QtCore.Qt.LeftButton:
            self.startPos = event.pos()

    def mouseMoveEvent(self, event):
        if self.startPos:
            self.move(self.pos() + (event.pos() - self.startPos))

    def mouseReleaseEvent(self, event):
        self.startPos = None


class GraphicsRoundedFrame(QtWidgets.QGraphicsProxyWidget):
    def __init__(self):
        super().__init__()

        self.container = Container()
        self.setWidget(self.container)

    def addWidget(self, widget):
        self.container.layout().addWidget(widget)

    def paint(self, qp, opt, widget):
        qp.save()
        p = QtGui.QPainterPath()
        p.addRoundedRect(self.boundingRect().adjusted(0, 0, -.5, -.5), 4, 4)
        qp.setClipPath(p)
        super().paint(qp, opt, widget)
        qp.restore()


class View(QtWidgets.QGraphicsView):
    def __init__(self):
        super().__init__()

        scene = QtWidgets.QGraphicsScene()
        self.setScene(scene)
        self.setRenderHints(QtGui.QPainter.Antialiasing)
        scene.setSceneRect(0, 0, 1024, 768)

        texture = QtGui.QImage(30, 30, QtGui.QImage.Format_ARGB32)
        qp = QtGui.QPainter(texture)
        qp.setBrush(QtCore.Qt.white)
        qp.setPen(QtGui.QPen(QtGui.QColor(189, 190, 191), 2))
        qp.drawRect(texture.rect())
        qp.end()
        scene.setBackgroundBrush(QtGui.QBrush(texture))

        testFrame = GraphicsRoundedFrame()
        scene.addItem(testFrame)
        testFrame.container.layout().addStretch(1)
        testFrame.addWidget(QtWidgets.QPushButton('I am a button'))


if __name__ == '__main__':
    import sys

    app = QtWidgets.QApplication(sys.argv)
    w = View()
    w.show()
    sys.exit(app.exec_())
python ооп
  • 1 个回答
  • 33 Views
Martin Hope
ардуино IDE
Asked: 2022-07-07 13:15:51 +0000 UTC

用python判断一个句子中的大小写

  • 2

你好亲爱的程序员,我知道这听起来很奇怪,但我需要在一个句子(俄语)中确定大小写。

例如:他有问题 - 主格。问题的相关性 - 属格。他对这个问题不满意 - 与格

我尝试了带有变格和单词描述的网站https://ru.wiktionary.org/

更新:denisnumb,您可以通过某种方式将句子中的名词替换为其同义词,从而保留大小写。在我的示例中,我们找到一个同义词并根据您的示例替换它。

我只写了一个解析器,它确定单词的同义词并逐个变化单词:

import requests
from bs4 import BeautifulSoup

s = "проблемы".lower()

word_s = requests.get("https://ru.wiktionary.org/w/index.php", {"search": s})


word = BeautifulSoup(word_s.text, 'lxml')
quote = word.find('span', class_="mw-headline", id="Синонимы")
print(quote.next.next.next.text)
print(quote.next.next.next.a.get("href"))
quote1 = word.find('table', class_="morfotable ru")
cases = quote1.tbody.find_all("tr")
case_l = []
for case in cases:
    _ = []
    for i in case.find_all("td"):
        a = i.text.replace("́", "").replace("\n", "")  # Здесь убирается ударение, символ ударения сюда не скопировался.
        _.append(a)
        if a == s:
            print(_[0], a)
    case_l.append(_)
print(case_l)
python requests
  • 1 个回答
  • 90 Views
Martin Hope
ардуино IDE
Asked: 2022-06-27 12:48:28 +0000 UTC

用户调整小部件的大小

  • 1

有没有办法让QWidget用户调整大小。也就是说,通过用鼠标拖动。

更新:调整大小QWidget需要在所有方面进行。

主文件

from PyQt5.QtCore import *
from PyQt5.QtGui import *
from PyQt5.QtWidgets import *


class DragButton(QPushButton):

    def mousePressEvent(self, event):
        self.__mousePressPos = None
        self.__mouseMovePos = None
        if event.button() == Qt.LeftButton:
            self.__mousePressPos = event.globalPos()
            self.__mouseMovePos = event.globalPos()

        super(DragButton, self).mousePressEvent(event)

    def mouseMoveEvent(self, event):
        if event.buttons() == Qt.LeftButton:
            currPos = self.mapToGlobal(self.pos())
            globalPos = event.globalPos()
            diff = globalPos - self.__mouseMovePos
            newPos = self.mapFromGlobal(currPos + diff)
            self.move(newPos)

            self.__mouseMovePos = globalPos

        super(DragButton, self).mouseMoveEvent(event)

    def mouseReleaseEvent(self, event):
        if self.__mousePressPos is not None:
            moved = event.globalPos() - self.__mousePressPos
            if moved.manhattanLength() > 3:
                event.ignore()
                return

        super(DragButton, self).mouseReleaseEvent(event)

if __name__ == "__main__":
    app = QApplication([])
    w = QWidget()
    w.resize(800,600)

    button = DragButton("Drag", w)

    w.show()
    app.exec_()

以及如何尝试调整大小粘贴?

python
  • 0 个回答
  • 0 Views
Martin Hope
ардуино IDE
Asked: 2022-07-04 16:34:34 +0000 UTC

在 Python 中不使用库进行解析 [关闭]

  • -2
关闭 这个问题是题外话。目前不接受回复。

仅当您在提出问题之前尝试自己解决问题时,才允许将学习问题作为问题。请编辑问题并指出究竟是什么导致您难以解决问题。例如,请提供您在尝试解决问题时编写的代码

8 个月前关闭。

改进问题

我有这一行,它需要在不使用库的情况下进行解析,只使用 python 3 本身:

command s1 s2 (l1 l2) [lp 990] (l [li p]) "entity j [90 90]" <ping 90> *9 9* lol

需要获得:

['command', 's1', 's2', {'strings': ['l1', 'l2'], type: 'round_brackets'}, {'strings': ['lp', '990'], type: 'square_brackets'}, {'strings': ['l', {'strings': ['li', 'p'], type: 'square_brackets'}], type: 'round_brackets'}, {'strings': 'entity j [90 90]', type: 'quotes'}, {'strings': ['ping', '90'], type: 'command'}, {'integers': ['9', '9'], type: 'nums'}, 'lol']

解析规则:

  1. 括号和引号和星号可以嵌套
  2. 解析在引号中不起作用。
  3. 用星星代替字符串整数。
  4. 在结果数组中,其字典将包含内容本身和类型。

这就是您需要做的所有事情,请谁能做到:)。

而且我无法使用列表中的字典编写解析器。

python
  • 1 个回答
  • 10 Views
Martin Hope
ардуино IDE
Asked: 2022-03-27 16:51:59 +0000 UTC

在 Python 中拆分字符串

  • 1

我想在空格上分割字符串,而不是在 ()、"" 和 [] 之间分割。

行示例:

set 1 test "favorite text" get (user get "li 1 0") [0, 1, "po"]

预期结果:

['set', '1', 'test', '"favorite text"', 'get', '(user get "li 1 0")', '[0, 1, "po"]']

这是命令处理所必需的。

python
  • 1 个回答
  • 10 Views

Sidebar

Stats

  • 问题 10021
  • Answers 30001
  • 最佳答案 8000
  • 用户 6900
  • 常问
  • 回答
  • Marko Smith

    我看不懂措辞

    • 1 个回答
  • Marko Smith

    请求的模块“del”不提供名为“default”的导出

    • 3 个回答
  • Marko Smith

    "!+tab" 在 HTML 的 vs 代码中不起作用

    • 5 个回答
  • Marko Smith

    我正在尝试解决“猜词”的问题。Python

    • 2 个回答
  • Marko Smith

    可以使用哪些命令将当前指针移动到指定的提交而不更改工作目录中的文件?

    • 1 个回答
  • Marko Smith

    Python解析野莓

    • 1 个回答
  • Marko Smith

    问题:“警告:检查最新版本的 pip 时出错。”

    • 2 个回答
  • Marko Smith

    帮助编写一个用值填充变量的循环。解决这个问题

    • 2 个回答
  • Marko Smith

    尽管依赖数组为空,但在渲染上调用了 2 次 useEffect

    • 2 个回答
  • Marko Smith

    数据不通过 Telegram.WebApp.sendData 发送

    • 1 个回答
  • Martin Hope
    Alexandr_TT 2020年新年大赛! 2020-12-20 18:20:21 +0000 UTC
  • Martin Hope
    Alexandr_TT 圣诞树动画 2020-12-23 00:38:08 +0000 UTC
  • Martin Hope
    Air 究竟是什么标识了网站访问者? 2020-11-03 15:49:20 +0000 UTC
  • Martin Hope
    Qwertiy 号码显示 9223372036854775807 2020-07-11 18:16:49 +0000 UTC
  • Martin Hope
    user216109 如何为黑客设下陷阱,或充分击退攻击? 2020-05-10 02:22:52 +0000 UTC
  • Martin Hope
    Qwertiy 并变成3个无穷大 2020-11-06 07:15:57 +0000 UTC
  • Martin Hope
    koks_rs 什么是样板代码? 2020-10-27 15:43:19 +0000 UTC
  • Martin Hope
    Sirop4ik 向 git 提交发布的正确方法是什么? 2020-10-05 00:02:00 +0000 UTC
  • Martin Hope
    faoxis 为什么在这么多示例中函数都称为 foo? 2020-08-15 04:42:49 +0000 UTC
  • Martin Hope
    Pavel Mayorov 如何从事件或回调函数中返回值?或者至少等他们完成。 2020-08-11 16:49:28 +0000 UTC

热门标签

javascript python java php c# c++ html android jquery mysql

Explore

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

Footer

RError.com

关于我们

  • 关于我们
  • 联系我们

Legal Stuff

  • Privacy Policy

帮助

© 2023 RError.com All Rights Reserve   沪ICP备12040472号-5