5

特别是我有两个问题:

1)如何去除小部件之间的细线?setMargin(0) 和 setSpacing(0) 已经设置好了。

2)在进一步的步骤中,我想用 FramelessWindowHint 删除窗口标题栏。要拖动窗口,我将在上部深黄色小部件上绑定一个 mouseevent。现在,上面的小部件是一个带有抑制键盘交互的 QTextEdit。出于拖动目的,我怀疑这个小部件是否很好......所以问题是,还有哪些其他小部件可以很好地创建一个彩色手柄来拖动窗口?也许是QLabel?

在此处输入图像描述

编辑:这是代码。我只使用了 QTestEdit-Widgets。

from PyQt4.QtGui import *
from PyQt4 import QtGui,QtCore
import sys

class Note(QWidget):
    def __init__(self, parent = None):
        super(QWidget, self).__init__(parent)
        self.createLayout()
        self.setWindowTitle("Note")

    def createLayout(self):
        textedit = QTextEdit()
        grip = QTextEdit()
        grip.setMaximumHeight(16) #reduces the upper text widget to a height to look like a grip of a note
        grip.setVerticalScrollBarPolicy(QtCore.Qt.ScrollBarAlwaysOff) #suppresses the scroll bar that appears under a certain height
        empty = QTextEdit()
        empty.setMaximumHeight(16)
        empty.setVerticalScrollBarPolicy(QtCore.Qt.ScrollBarAlwaysOff)
        resize = QTextEdit()
        resize.setMaximumHeight(16)        
        resize.setMaximumWidth(16)
        resize.setVerticalScrollBarPolicy(QtCore.Qt.ScrollBarAlwaysOff)

        layout = QVBoxLayout()
        layout.addWidget(grip)
        layout.addWidget(textedit)

        layout.setMargin(0)
        layout.setSpacing(0)

        layoutBottom=QHBoxLayout()
        layoutBottom.addWidget(empty)
        layoutBottom.addWidget(resize)
        layout.addLayout(layoutBottom)

        self.setLayout(layout)

        # Set Font
        textedit.setFont(QFont("Arial",16))

        # Set Color
        pal=QtGui.QPalette()
        rgb=QtGui.QColor(232,223,80) #Textwidget BG = yellow
        pal.setColor(QtGui.QPalette.Base,rgb)
        textc=QtGui.QColor(0,0,0) 
        pal.setColor(QtGui.QPalette.Text,textc)
        textedit.setPalette(pal)
        empty.setPalette(pal)

        pal_grip=QtGui.QPalette()
        rgb_grip = QtGui.QColor(217,207,45) 
        pal_grip.setColor(QtGui.QPalette.Base,rgb_grip)
        textc_grip=QtGui.QColor(0,0,0)
        pal.setColor(QtGui.QPalette.Text,textc_grip)
        grip.setPalette(pal_grip)
        resize.setPalette(pal_grip)

        resize.setTextInteractionFlags(QtCore.Qt.NoTextInteraction)
        empty.setTextInteractionFlags(QtCore.Qt.NoTextInteraction)
        grip.setTextInteractionFlags(QtCore.Qt.NoTextInteraction)

        #textedit.setTextInteractionFlags(QtCore.Qt.NoTextInteraction) #total text widget lock
        #textedit.setTextInteractionFlags(QtCore.Qt.TextSelectableByMouse) #Lock?
        #http://qt-project.org/doc/qt-4.8/qt.html#TextInteractionFlag-enum

        #self.setWindowFlags(QtCore.Qt.FramelessWindowHint) #removes the title bar

        #self.setWindowFlags(QtCore.Qt.WindowStaysOnTopHint) #to make the window stay on top

class Main():
    def __init__(self):
        self.notes=[]
        self.app = QApplication(sys.argv)
        self.app.setQuitOnLastWindowClosed(False);

        self.trayIcon = QSystemTrayIcon(QIcon(r"C:\Users\Thomas\Desktop\SimpleNotes.ico"), self.app)
        self.menu = QMenu()

        self.newWindow  =  self.menu.addAction("New note")
        self.separator  =  self.menu.addSeparator()
        self.hideNotes  =  self.menu.addAction("Hide all notes")
        self.showNotes  =  self.menu.addAction("Show all notes")
        self.separator  =  self.menu.addSeparator()
        self.saveNotes  =  self.menu.addAction("Save notes")
        self.loadNotes  =  self.menu.addAction("Load notes")
        self.separator  =  self.menu.addSeparator()
        self.showHelp   =  self.menu.addAction("Show help")
        self.showAbout  =  self.menu.addAction("Show about")
        self.separator  =  self.menu.addSeparator()
        self.exitAction =  self.menu.addAction("Quit notes")

        self.exitAction.triggered.connect(self.close)
        self.newWindow.triggered.connect(self.newNote)
        self.trayIcon.setContextMenu(self.menu)
        self.trayIcon.show()

        self.app.exec()

    def newNote(self):
        print("Create new note entry has been clicked")
        note=Note()
        note.show()
        self.notes.append(note)
        print(self.notes)

    def hideNotes(self):
        pass
    def showNotes(self):
        pass
    def saveNotes(self):
        pass
    def loadNotes(self):
        pass
    def showHelp(self):
        pass
    def showAbout(self):
        pass

    def close(self):
        self.trayIcon.hide()
        self.app.exit()
        print("Exit menu entry has been clicked")

if __name__ == '__main__':
    Main()
4

3 回答 3

7

thuga 的回答已经足够好了,所以我把它贴在这里:

textedit.setFrameShape(QtGui.QFrame.NoFrame)

grip.setFrameShape(QtGui.QFrame.NoFrame) 

使这条线消失了。

于 2013-05-29T12:01:41.387 回答
2

1.我用过:

textEdit.setFrameStyle(QtGui.QFrame.NoFrame)
于 2013-07-02T08:53:58.120 回答
1
ui->fr200->setFrameShape(QFrame::NoFrame);
ui->fr201->setFrameShape(QFrame::NoFrame);
ui->fr202->setFrameShape(QFrame::NoFrame);
ui->fr203->setFrameShape(QFrame::NoFrame);
ui->fr204->setFrameShape(QFrame::NoFrame);
ui->fr205->setFrameShape(QFrame::NoFrame);
ui->fr206->setFrameShape(QFrame::NoFrame);
ui->fr207->setFrameShape(QFrame::NoFrame);
ui->fr208->setFrameShape(QFrame::NoFrame);
于 2019-09-27T10:48:53.357 回答