devwiki:python_qt

Differences

This shows you the differences between two versions of the page.

Link to this comparison view

Both sides previous revision Previous revision
Next revision
Previous revision
devwiki:python_qt [2021/12/02 10:32] – [Break 1: Python 2 vs Python 3] yingdevwiki:python_qt [2024/01/10 03:08] (current) – [Layout and Container] ying
Line 366: Line 366:
   * get global text color <code python>   * get global text color <code python>
 text_color = self.palette().color(QtGui.QPalette.Text).name() text_color = self.palette().color(QtGui.QPalette.Text).name()
 +</code>
 +  * list all current color palette of default in app <code python>
 +from PySide2 import QtCore, QtGui, QtWidgets
 +import MyToolName
 +ui = MyToolName.main()
 +color_info = ui.palette().color(QtGui.QPalette.Dark).name()
 +print('color info {}'.format(color_info))
 +
 +color_roles = [
 +    QtGui.QPalette.WindowText, QtGui.QPalette.Button, QtGui.QPalette.Light, QtGui.QPalette.Midlight,
 +    QtGui.QPalette.Dark, QtGui.QPalette.Mid, QtGui.QPalette.Text, QtGui.QPalette.BrightText,
 +    QtGui.QPalette.ButtonText, QtGui.QPalette.Base, QtGui.QPalette.Window, QtGui.QPalette.Shadow,
 +    QtGui.QPalette.Highlight, QtGui.QPalette.HighlightedText, QtGui.QPalette.Link, QtGui.QPalette.LinkVisited,
 +    QtGui.QPalette.AlternateBase, QtGui.QPalette.NoRole
 +]
 +
 +print("Color roles and their corresponding colors:")
 +for role in color_roles:
 +    color = ui.palette().color(role)
 +    print(f"{role}: {color.name()}")
 </code> </code>
   * apply style sheet file <code python>   * apply style sheet file <code python>
Line 1141: Line 1161:
 my_layout.setAlignment(QtCore.Qt.AlignTop) my_layout.setAlignment(QtCore.Qt.AlignTop)
 </code> </code>
-  * QGridLayout <code python>my_grid_layout.setSpacing(0) # 0 tight grid like maya grid </code>+  * QGridLayout <code python>my_grid_layout.setSpacing(0) # 0 tight grid like maya grid  
 + 
 +# -- make grid equal size for all cells 
 +cur_layout = ui['region_grid'
 +# for i in range( cur_layout.rowCount() ): 
 +#    cur_layout.setRowStretch( i, 1) 
 +for j in range( cur_layout.columnCount() ): 
 +    cur_layout.setColumnStretch( j, 1 ) 
 + 
 +</code>
   * QFormLayout   * QFormLayout
   * QSplitter <code python>   * QSplitter <code python>
Line 1154: Line 1183:
     * customize look <code python>     * customize look <code python>
 my_tab.setStyleSheet("QTabWidget::tab-bar{alignment:center;}QTabBar::tab { min-width: 100px; }") my_tab.setStyleSheet("QTabWidget::tab-bar{alignment:center;}QTabBar::tab { min-width: 100px; }")
 +</code>
 +  * QScrollArea
 +    * put widget into a scroll area <code python>
 +# main_layout is top most layout
 +main_scroll = QtWidgets.QScrollArea()
 +main_scroll.setWidgetResizable(1)
 +
 +content_widget = QtWidgets.QWidget()
 +content_layout = QtWidgets.QVBoxLayout(content_widget)
 +
 +main_scroll.setWidget(content_widget)
 +
 +test_label = QtWidgets.QLabel('Example Text')
 +test_label.setTextInteractionFlags(QtCore.Qt.TextSelectableByMouse)
 +content_layout.addWidget(tmpLabel)
 +
 +main_layout.addWidget(main_scroll)
 +# optional
 +main_layout.setStyleSheet("QScrollArea{min-width:500 px; min-height: 400px}")
 </code> </code>
 ===== QWidget Property ===== ===== QWidget Property =====
Line 1181: Line 1229:
 self.uiList['user_input'].setDisabled(1) # grey out look, can use style to tune better self.uiList['user_input'].setDisabled(1) # grey out look, can use style to tune better
 self.uiList['user_input'].setReadOnly(1) # normal look, but not editable self.uiList['user_input'].setReadOnly(1) # normal look, but not editable
 +</code>
 +  * QLineEdit password hide <code python>
 +self.uiList['user_input'].setEchoMode(QtWidgets.QLineEdit.Password)
 </code> </code>
   * QTextEdit make it accept plain text only <code python>   * QTextEdit make it accept plain text only <code python>
Line 1373: Line 1424:
 # make tree item editable for all columes # make tree item editable for all columes
 new_node.setFlags(new_node.flags()|QtCore.Qt.ItemIsEditable) new_node.setFlags(new_node.flags()|QtCore.Qt.ItemIsEditable)
 +
 +# change align
 +new_node.setTextAlignment(i, QtCore.Qt.AlignRight )
 +
 +# change bg to pink
 +new_node.setBackgroundColor(0, QtGui.QColor(255,192,203, 100))
 +
 +# set to brush and reset to default
 +self.brush['fav'] = QtGui.QBrush(QtGui.QColor("#F280BF"))
 +currentNode.setBackground(0, self.brush['fav'])
 +currentNode.setData(0, QtCore.Qt.BackgroundRole, None)
 </code> </code>
   * make tree item editable only for some columes <code python>   * make tree item editable only for some columes <code python>
Line 1889: Line 1951:
     * so now I am moving to Qt + C++ solutions to explore more binary tools development using the same knowledge from python QT side.     * so now I am moving to Qt + C++ solutions to explore more binary tools development using the same knowledge from python QT side.
  
 +
 +====== Problem and Solution ======
 +
 +  * Problem: qt.qpa.fonts: Unable to open default EUDC font: "C:\\WINDOWS\\FONTS\\EUDC.TTE"
 +    * end-user-defined characters (EUDCs), just delete related regedit entry \HKEY_CURRENT_USER\EUDC\1252
 +    * ref: https://bugreports.qt.io/browse/PYSIDE-1620
  
  • devwiki/python_qt.1638441137.txt.gz
  • Last modified: 2021/12/02 10:32
  • by ying