久久久久久久av_日韩在线中文_看一级毛片视频_日本精品二区_成人深夜福利视频_武道仙尊动漫在线观看

<legend id='OVpeT'><style id='OVpeT'><dir id='OVpeT'><q id='OVpeT'></q></dir></style></legend>
  • <i id='OVpeT'><tr id='OVpeT'><dt id='OVpeT'><q id='OVpeT'><span id='OVpeT'><b id='OVpeT'><form id='OVpeT'><ins id='OVpeT'></ins><ul id='OVpeT'></ul><sub id='OVpeT'></sub></form><legend id='OVpeT'></legend><bdo id='OVpeT'><pre id='OVpeT'><center id='OVpeT'></center></pre></bdo></b><th id='OVpeT'></th></span></q></dt></tr></i><div class="qwawimqqmiuu" id='OVpeT'><tfoot id='OVpeT'></tfoot><dl id='OVpeT'><fieldset id='OVpeT'></fieldset></dl></div>
      <bdo id='OVpeT'></bdo><ul id='OVpeT'></ul>

    <small id='OVpeT'></small><noframes id='OVpeT'>

    1. <tfoot id='OVpeT'></tfoot>

      1. PyQt5中帶框架的自定義標題欄

        Custom Titlebar with frame in PyQt5(PyQt5中帶框架的自定義標題欄)
            <legend id='9nuLt'><style id='9nuLt'><dir id='9nuLt'><q id='9nuLt'></q></dir></style></legend>

            1. <tfoot id='9nuLt'></tfoot>
            2. <small id='9nuLt'></small><noframes id='9nuLt'>

                <tbody id='9nuLt'></tbody>
                <bdo id='9nuLt'></bdo><ul id='9nuLt'></ul>

                • <i id='9nuLt'><tr id='9nuLt'><dt id='9nuLt'><q id='9nuLt'><span id='9nuLt'><b id='9nuLt'><form id='9nuLt'><ins id='9nuLt'></ins><ul id='9nuLt'></ul><sub id='9nuLt'></sub></form><legend id='9nuLt'></legend><bdo id='9nuLt'><pre id='9nuLt'><center id='9nuLt'></center></pre></bdo></b><th id='9nuLt'></th></span></q></dt></tr></i><div class="qwawimqqmiuu" id='9nuLt'><tfoot id='9nuLt'></tfoot><dl id='9nuLt'><fieldset id='9nuLt'></fieldset></dl></div>
                  本文介紹了PyQt5中帶框架的自定義標題欄的處理方法,對大家解決問題具有一定的參考價值,需要的朋友們下面隨著小編來一起學習吧!

                  問題描述

                  我正在開發一個支持開源降價的 Windows/Linux 最小筆記應用程序.我正在嘗試刪除標題欄并添加我自己的按鈕.我想要一個只有兩個自定義按鈕的標題欄,如圖

                  目前我有這個:

                  我試過修改窗口標志:

                  • 沒有窗口標志,窗口既可調整大小又可移動.但沒有自定義按鈕.
                  • 使用self.setWindowFlags(QtCore.Qt.FramelessWindowHint),窗口沒有邊框,但不能移動或調整窗口大小
                  • 使用self.setWindowFlags(QtCore.Qt.CustomizeWindowHint),窗口可以調整大小但不能移動,也不能去掉窗口頂部的白色部分.

                  任何幫助表示贊賞.您可以在 GitHub

                  解決方案

                  以下是您必須遵循的步驟:

                  1. 擁有您的 MainWindow,無論是 QMainWindow、QWidget,還是您想要繼承的任何 [widget].
                  2. 設置它的標志,self.setWindowFlags(Qt.FramelessWindowHint)
                  3. 實現自己的移動.
                  4. 實現您自己的按鈕(關閉、最大、最小)
                  5. 實現您自己的調整大小.

                  這里有一個小例子,它實現了移動和按鈕.您仍然應該使用相同的邏輯來實現調整大小.

                  導入系統從 PyQt5.QtCore 導入 QPoint從 PyQt5.QtCore 導入 Qt從 PyQt5.QtWidgets 導入 QApplication從 PyQt5.QtWidgets 導入 QHBoxLayout從 PyQt5.QtWidgets 導入 QLabel從 PyQt5.QtWidgets 導入 QPushButton從 PyQt5.QtWidgets 導入 QVBoxLayout從 PyQt5.QtWidgets 導入 QWidget類主窗口(QWidget):def __init__(self):超級(主窗口,自我).__init__()self.layout = QVBoxLayout()self.layout.addWidget(MyBar(self))self.setLayout(self.layout)self.layout.setContentsMargins(0,0,0,0)self.layout.addStretch(-1)self.setMinimumSize(800,400)self.setWindowFlags(Qt.FramelessWindowHint)self.pressing = FalseMyBar 類(QWidget):def __init__(自我,父母):超級(我的酒吧,自我).__init__()self.parent = 父母打印(self.parent.width())self.layout = QHBoxLayout()self.layout.setContentsMargins(0,0,0,0)self.title = QLabel("我自己的酒吧")btn_size = 35self.btn_close = QPushButton("x")self.btn_close.clicked.connect(self.btn_close_clicked)self.btn_close.setFixedSize(btn_size,btn_size)self.btn_close.setStyleSheet("背景色:紅色;")self.btn_min = QPushButton("-")self.btn_min.clicked.connect(self.btn_min_clicked)self.btn_min.setFixedSize(btn_size, btn_size)self.btn_min.setStyleSheet("背景色:灰色;")self.btn_max = QPushButton("+")self.btn_max.clicked.connect(self.btn_max_clicked)self.btn_max.setFixedSize(btn_size, btn_size)self.btn_max.setStyleSheet("背景色:灰色;")self.title.setFixedHeight(35)self.title.setAlignment(Qt.AlignCenter)self.layout.addWidget(self.title)self.layout.addWidget(self.btn_min)self.layout.addWidget(self.btn_max)self.layout.addWidget(self.btn_close)self.title.setStyleSheet("""背景顏色:黑色;白顏色;""")self.setLayout(self.layout)self.start = QPoint(0, 0)self.pressing = Falsedef resizeEvent(self, QResizeEvent):超級(MyBar,自我).resizeEvent(QResizeEvent)self.title.setFixedWidth(self.parent.width())def mousePressEvent(自我,事件):self.start = self.mapToGlobal(event.pos())self.pressing = 真def mouseMoveEvent(自我,事件):如果自壓:self.end = self.mapToGlobal(event.pos())self.movement = self.end-self.startself.parent.setGeometry(self.mapToGlobal(self.movement).x(),self.mapToGlobal(self.movement).y(),self.parent.width(),self.parent.height())self.start = self.enddef mouseReleaseEvent(self, QMouseEvent):self.pressing = Falsedef btn_close_clicked(self):self.parent.close()def btn_max_clicked(self):self.parent.showMaximized()def btn_min_clicked(self):self.parent.showMinimized()如果 __name__ == "__main__":應用程序 = QApplication(sys.argv)mw = 主窗口()mw.show()sys.exit(app.exec_())

                  這里有一些提示:

                  選項 1:

                  1. 在每個角落和側面都有一個帶有小部件的 QGridLayout(例如左、左上、菜單欄、右上、右、右下、右下和左下)
                  2. 使用方法 (1),您會知道在單擊每個邊框時,您只需定義每個尺寸并將每個尺寸添加到它們的位置.
                  3. 當你點擊每一個時,以各自的方式對待它們,例如,如果你點擊左邊的并拖動到左邊,你必須將它調整大,同時將它向左移動,這樣它就會似乎停在了正確的位置并增加了寬度.
                  4. 將此推理應用于每個邊緣,每個邊緣都以它必須的方式行事.

                  選項 2:

                  1. 您可以通過點擊位置檢測您正在點擊的位置,而不是使用 QGridLayout.

                  2. 驗證點擊的x是否小于移動位置的x,以了解它是向左還是向右移動以及被點擊的位置.

                  3. 計算方法同Option1

                  選項 3:

                  1. 可能還有其他方法,但我只是想到了這些.例如,使用您說可以調整大小的 CustomizeWindowHint,因此您只需要實現我給您的示例即可.漂亮!

                  提示:

                  1. 小心localPos(在自己的小部件內部),globalPos(與您的屏幕相關).例如:如果您單擊左側小部件的最左側,它的x"將為零,如果您單擊中間(內容)的最左側,它也將為零,盡管如果您 mapToGlobal 您將有不同的值根據屏幕的位置.
                  2. 在調整大小或移動時要注意,當您必須增加寬度或減少寬度,或者只是移動,或兩者兼而有之時,我建議您在實施之前先在紙上繪制并弄清楚調整大小的邏輯是如何工作的藍色的.

                  祝你好運:D

                  I'm working on an opensource markdown supported minimal note taking application for Windows/Linux. I'm trying to remove the title bar and add my own buttons. I want something like, a title bar with only two custom buttons as shown in the figure

                  Currently I have this:

                  I've tried modifying the window flags:

                  • With not window flags, the window is both re-sizable and movable. But no custom buttons.
                  • Using self.setWindowFlags(QtCore.Qt.FramelessWindowHint), the window has no borders, but cant move or resize the window
                  • Using self.setWindowFlags(QtCore.Qt.CustomizeWindowHint), the window is resizable but cannot move and also cant get rid of the white part at the top of the window.

                  Any help appreciated. You can find the project on GitHub here.

                  Thanks..

                  This is my python code:

                  from PyQt5 import QtCore, QtWidgets, QtWebEngineWidgets, uic
                  import sys
                  import os
                  import markdown2 # https://github.com/trentm/python-markdown2
                  from PyQt5.QtCore import QRect
                  from PyQt5.QtGui import QFont
                  
                  simpleUiForm = uic.loadUiType("Simple.ui")[0]
                  
                  class SimpleWindow(QtWidgets.QMainWindow, simpleUiForm):
                      def __init__(self, parent=None):
                          QtWidgets.QMainWindow.__init__(self, parent)
                          self.setupUi(self)
                          self.markdown = markdown2.Markdown()
                          self.css = open(os.path.join("css", "default.css")).read()
                          self.editNote.setPlainText("")
                          #self.noteView = QtWebEngineWidgets.QWebEngineView(self)
                          self.installEventFilter(self)
                          self.displayNote.setContextMenuPolicy(QtCore.Qt.NoContextMenu)
                          #self.setWindowFlags(QtCore.Qt.FramelessWindowHint)
                  
                      def eventFilter(self, object, event):
                          if event.type() == QtCore.QEvent.WindowActivate:
                              print("widget window has gained focus")
                              self.editNote.show()
                              self.displayNote.hide()
                          elif event.type() == QtCore.QEvent.WindowDeactivate:
                              print("widget window has lost focus")
                              note = self.editNote.toPlainText()
                              htmlNote = self.getStyledPage(note)
                              # print(note)
                              self.editNote.hide()
                              self.displayNote.show()
                              # print(htmlNote)
                              self.displayNote.setHtml(htmlNote)
                          elif event.type() == QtCore.QEvent.FocusIn:
                              print("widget has gained keyboard focus")
                          elif event.type() == QtCore.QEvent.FocusOut:
                              print("widget has lost keyboard focus")
                          return False
                  

                  The UI file is created in the following hierarchy

                  解決方案

                  Here are the steps you just gotta follow:

                  1. Have your MainWindow, be it a QMainWindow, or QWidget, or whatever [widget] you want to inherit.
                  2. Set its flag, self.setWindowFlags(Qt.FramelessWindowHint)
                  3. Implement your own moving around.
                  4. Implement your own buttons (close, max, min)
                  5. Implement your own resize.

                  Here is a small example with move around, and buttons implemented. You should still have to implement the resize using the same logic.

                  import sys
                  
                  from PyQt5.QtCore import QPoint
                  from PyQt5.QtCore import Qt
                  from PyQt5.QtWidgets import QApplication
                  from PyQt5.QtWidgets import QHBoxLayout
                  from PyQt5.QtWidgets import QLabel
                  from PyQt5.QtWidgets import QPushButton
                  from PyQt5.QtWidgets import QVBoxLayout
                  from PyQt5.QtWidgets import QWidget
                  
                  
                  
                  class MainWindow(QWidget):
                  
                      def __init__(self):
                          super(MainWindow, self).__init__()
                          self.layout  = QVBoxLayout()
                          self.layout.addWidget(MyBar(self))
                          self.setLayout(self.layout)
                          self.layout.setContentsMargins(0,0,0,0)
                          self.layout.addStretch(-1)
                          self.setMinimumSize(800,400)
                          self.setWindowFlags(Qt.FramelessWindowHint)
                          self.pressing = False
                  
                  
                  class MyBar(QWidget):
                  
                      def __init__(self, parent):
                          super(MyBar, self).__init__()
                          self.parent = parent
                          print(self.parent.width())
                          self.layout = QHBoxLayout()
                          self.layout.setContentsMargins(0,0,0,0)
                          self.title = QLabel("My Own Bar")
                  
                          btn_size = 35
                  
                          self.btn_close = QPushButton("x")
                          self.btn_close.clicked.connect(self.btn_close_clicked)
                          self.btn_close.setFixedSize(btn_size,btn_size)
                          self.btn_close.setStyleSheet("background-color: red;")
                  
                          self.btn_min = QPushButton("-")
                          self.btn_min.clicked.connect(self.btn_min_clicked)
                          self.btn_min.setFixedSize(btn_size, btn_size)
                          self.btn_min.setStyleSheet("background-color: gray;")
                  
                          self.btn_max = QPushButton("+")
                          self.btn_max.clicked.connect(self.btn_max_clicked)
                          self.btn_max.setFixedSize(btn_size, btn_size)
                          self.btn_max.setStyleSheet("background-color: gray;")
                  
                          self.title.setFixedHeight(35)
                          self.title.setAlignment(Qt.AlignCenter)
                          self.layout.addWidget(self.title)
                          self.layout.addWidget(self.btn_min)
                          self.layout.addWidget(self.btn_max)
                          self.layout.addWidget(self.btn_close)
                  
                          self.title.setStyleSheet("""
                              background-color: black;
                              color: white;
                          """)
                          self.setLayout(self.layout)
                  
                          self.start = QPoint(0, 0)
                          self.pressing = False
                  
                      def resizeEvent(self, QResizeEvent):
                          super(MyBar, self).resizeEvent(QResizeEvent)
                          self.title.setFixedWidth(self.parent.width())
                  
                      def mousePressEvent(self, event):
                          self.start = self.mapToGlobal(event.pos())
                          self.pressing = True
                  
                      def mouseMoveEvent(self, event):
                          if self.pressing:
                              self.end = self.mapToGlobal(event.pos())
                              self.movement = self.end-self.start
                              self.parent.setGeometry(self.mapToGlobal(self.movement).x(),
                                                  self.mapToGlobal(self.movement).y(),
                                                  self.parent.width(),
                                                  self.parent.height())
                              self.start = self.end
                  
                      def mouseReleaseEvent(self, QMouseEvent):
                          self.pressing = False
                  
                  
                      def btn_close_clicked(self):
                          self.parent.close()
                  
                      def btn_max_clicked(self):
                          self.parent.showMaximized()
                  
                      def btn_min_clicked(self):
                          self.parent.showMinimized()
                  
                  
                  if __name__ == "__main__":
                      app = QApplication(sys.argv)
                      mw = MainWindow()
                      mw.show()
                      sys.exit(app.exec_())
                  

                  Here are some tips:

                  Option 1:

                  1. Have a QGridLayout with widget in each corner and side(e.g. left, top-left, menubar, top-right, right, bottom-right, bottom and bottom left)
                  2. With the approach (1) you would know when you are clicking in each border, you just got to define each one size and add each one on their place.
                  3. When you click on each one treat them in their respective ways, for example, if you click in the left one and drag to the left, you gotta resize it larger and at the same time move it to the left so it will appear to be stopped at the right place and grow width.
                  4. Apply this reasoning to each edge, each one behaving in the way it has to.

                  Option 2:

                  1. Instead of having a QGridLayout you can detect in which place you are clicking by the click pos.

                  2. Verify if the x of the click is smaller than the x of the moving pos to know if it's moving left or right and where it's being clicked.

                  3. The calculation is made in the same way of the Option1

                  Option 3:

                  1. Probably there are other ways, but those are the ones I just thought of. For example using the CustomizeWindowHint you said you are able to resize, so you just would have to implement what I gave you as example. BEAUTIFUL!

                  Tips:

                  1. Be careful with the localPos(inside own widget), globalPos(related to your screen). For example: If you click in the very left of your left widget its 'x' will be zero, if you click in the very left of the middle(content)it will be also zero, although if you mapToGlobal you will having different values according to the pos of the screen.
                  2. Pay attention when resizing, or moving, when you have to add width or subtract, or just move, or both, I'd recommend you to draw on a paper and figure out how the logic of resizing works before implementing it out of blue.

                  GOOD LUCK :D

                  這篇關于PyQt5中帶框架的自定義標題欄的文章就介紹到這了,希望我們推薦的答案對大家有所幫助,也希望大家多多支持html5模板網!

                  【網站聲明】本站部分內容來源于互聯網,旨在幫助大家更快的解決問題,如果有圖片或者內容侵犯了您的權益,請聯系我們刪除處理,感謝您的支持!

                  相關文檔推薦

                  How to bind a function to an Action from Qt menubar?(如何將函數綁定到 Qt 菜單欄中的操作?)
                  PyQt progress jumps to 100% after it starts(PyQt 啟動后進度躍升至 100%)
                  How to set yaxis tick label in a fixed position so that when i scroll left or right the yaxis tick label should be visible?(如何將 yaxis 刻度標簽設置在固定位置,以便當我向左或向右滾動時,yaxis 刻度標簽應該可見
                  `QImage` constructor has unknown keyword `data`(`QImage` 構造函數有未知關鍵字 `data`)
                  Change x-axis ticks to custom strings(將 x 軸刻度更改為自定義字符串)
                  How to show progress bar while saving file to excel in python?(如何在python中將文件保存為excel時顯示進度條?)

                          <legend id='Udsi9'><style id='Udsi9'><dir id='Udsi9'><q id='Udsi9'></q></dir></style></legend>

                        • <i id='Udsi9'><tr id='Udsi9'><dt id='Udsi9'><q id='Udsi9'><span id='Udsi9'><b id='Udsi9'><form id='Udsi9'><ins id='Udsi9'></ins><ul id='Udsi9'></ul><sub id='Udsi9'></sub></form><legend id='Udsi9'></legend><bdo id='Udsi9'><pre id='Udsi9'><center id='Udsi9'></center></pre></bdo></b><th id='Udsi9'></th></span></q></dt></tr></i><div class="qwawimqqmiuu" id='Udsi9'><tfoot id='Udsi9'></tfoot><dl id='Udsi9'><fieldset id='Udsi9'></fieldset></dl></div>
                            <tbody id='Udsi9'></tbody>
                          <tfoot id='Udsi9'></tfoot>

                          <small id='Udsi9'></small><noframes id='Udsi9'>

                            <bdo id='Udsi9'></bdo><ul id='Udsi9'></ul>

                            主站蜘蛛池模板: 拍真实国产伦偷精品 | www.亚洲| 日韩精品 电影一区 亚洲 | 亚洲精品一区二区三区丝袜 | 精品久久久久久久 | 国产激情视频网站 | 日韩成人精品在线观看 | 国产成人免费视频 | 天天干干| 国产精品久久久久久久7电影 | 免费激情av | 一区二区不卡视频 | 日本精品一区二区在线观看 | 亚洲国产精品99久久久久久久久 | 国产日产精品一区二区三区四区 | 欧美激情在线播放 | 午夜精品视频 | 九九伊人sl水蜜桃色推荐 | 在线播放国产一区二区三区 | 亚洲黄色av | 久一精品| 黄色一级毛片 | 女同av亚洲女人天堂 | 亚洲精品一区二区三区蜜桃久 | 黄色三级免费 | 久久国产秒 | 欧美亚洲国产一区二区三区 | 国产 日韩 欧美 在线 | 狠狠躁天天躁夜夜躁婷婷老牛影视 | 国产成人影院 | 欧美一区二区三区的 | 九九一级片 | 99精品免费在线观看 | 一级视频黄色 | 欧美日韩一区二区三区四区 | 一区精品在线观看 | 天天澡天天狠天天天做 | 欧美国产91 | av在线成人 | aaa精品 | 午夜国产羞羞视频免费网站 |