5
votes

In particular I have 2 questions:

1) How can I remove those thin lines between the widgets? setMargin(0) and setSpacing(0) are already set.

2) In a further step I want to remove the window title bar with FramelessWindowHint. To drag the window, I'll bind a mouseevent on the upper dark yellow widget. Right now, the upper widget is a QTextEdit with suppressed keyboard interactions. For the draging purpose, I doubt this widget is good... So the question is, what other widgets are good to create a colored handle to drag the window? Perhaps QLabel?

enter image description here

EDIT: Here is the code. I only used 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()
3
Which widgets and layout/containers are you using? - Frank Osterfeld
Paste some code so we can help you - Nicola
Ok, i added the code. I only used QTextWidgets. As i made the notes prior to Qt with tkinter, I used Frames as a handle... not sure if Qt has the same, because an empty frame seems to get pushed away by the text widget? - user2366975
If I understand correctly what you mean with thin borders, you can use setFrameStyle function for your QTextEdit's. Is that what you were looking for? - thuga
yes, thanks! textedit.setFrameShape(QtGui.QFrame.NoFrame) and grip.setFrameShape(QtGui.QFrame.NoFrame) made the line disappear. And to my second question: Are the TextEdit-Widgets good for draging the window or is a different widget better? - user2366975

3 Answers

7
votes

The answer from thuga was good enough, so i post it here:

textedit.setFrameShape(QtGui.QFrame.NoFrame)

and

grip.setFrameShape(QtGui.QFrame.NoFrame) 

made the line disappear.

2
votes

for 1. I've used:

textEdit.setFrameStyle(QtGui.QFrame.NoFrame)
0
votes
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);