Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Removing thin borders between widgets in Qt

Tags:

python

qt

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()
like image 555
user2366975 Avatar asked May 27 '13 20:05

user2366975


1 Answers

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.

like image 86
user2366975 Avatar answered Sep 19 '22 15:09

user2366975