Making Qt Application that work with different System Font Sizes -


i working on qt application targeting windows , mac os x. have lots of dialogs text in application. created application on windows, sized dialogs fit of text neatly. compiled on mac os x, realised of text doesn't fit properly. furthermore, setting different system font size in windows control panel causes of dialog sizes incorrect.

how supposed handle different system font sizes in qt?

you don't: let qt job you. use layouts arrange widgets; avoid setting fixed sizes. last point: recommend use qt-designer create interfaces.

edit dmitry: here python files 2 ui files (generated pyuic4) each 1 2 qlabel. 1 qlabel font huge (72), other default 1 (10).

  1. min , max size constrained: here if max font size 10, label correctly displayed.

    from pyqt4 import qtcore, qtgui  class ui_dialog(object):     def setupui(self, dialog):         dialog.setobjectname("dialog")         dialog.resize(115, 160)         sizepolicy = qtgui.qsizepolicy(qtgui.qsizepolicy.fixed, qtgui.qsizepolicy.fixed)         sizepolicy.sethorizontalstretch(0)         sizepolicy.setverticalstretch(0)         sizepolicy.setheightforwidth(dialog.sizepolicy().hasheightforwidth())         dialog.setsizepolicy(sizepolicy)         dialog.setminimumsize(qtcore.qsize(115, 160))         dialog.setmaximumsize(qtcore.qsize(115, 160))         self.verticallayout = qtgui.qvboxlayout(dialog)         self.verticallayout.setobjectname("verticallayout")         self.label = qtgui.qlabel(dialog)         font = qtgui.qfont()         font.setfamily("andale mono")         font.setpointsize(72)         self.label.setfont(font)         self.label.setobjectname("label")         self.verticallayout.addwidget(self.label)         self.label_2 = qtgui.qlabel(dialog)         self.label_2.setobjectname("label_2")         self.verticallayout.addwidget(self.label_2)          self.retranslateui(dialog)         qtcore.qmetaobject.connectslotsbyname(dialog)      def retranslateui(self, dialog):         dialog.setwindowtitle(qtgui.qapplication.translate("dialog", "dialog", none, qtgui.qapplication.unicodeutf8))         self.label.settext(qtgui.qapplication.translate("dialog", "ugly", none, qtgui.qapplication.unicodeutf8))         self.label_2.settext(qtgui.qapplication.translate("dialog", "not ugly", none, qtgui.qapplication.unicodeutf8))   if __name__ == "__main__":     import sys     app = qtgui.qapplication(sys.argv)     dialog = qtgui.qdialog()     ui = ui_dialog()     ui.setupui(dialog)     dialog.show()     sys.exit(app.exec_()) 
  2. no more constraint on size: label font size 72 can displayed.

    from pyqt4 import qtcore, qtgui  class ui_dialog(object):     def setupui(self, dialog):         dialog.setobjectname("dialog")         dialog.resize(495, 140)         self.verticallayout = qtgui.qvboxlayout(dialog)         self.verticallayout.setobjectname("verticallayout")         self.label = qtgui.qlabel(dialog)         font = qtgui.qfont()         font.setfamily("andale mono")         font.setpointsize(72)         self.label.setfont(font)         self.label.setobjectname("label")         self.verticallayout.addwidget(self.label)         self.label_2 = qtgui.qlabel(dialog)         self.label_2.setobjectname("label_2")         self.verticallayout.addwidget(self.label_2)          self.retranslateui(dialog)         qtcore.qmetaobject.connectslotsbyname(dialog)      def retranslateui(self, dialog):         dialog.setwindowtitle(qtgui.qapplication.translate("dialog", "dialog", none, qtgui.qapplication.unicodeutf8))         self.label.settext(qtgui.qapplication.translate("dialog", "less ugly", none, qtgui.qapplication.unicodeutf8))         self.label_2.settext(qtgui.qapplication.translate("dialog", "not ugly", none, qtgui.qapplication.unicodeutf8))   if __name__ == "__main__":     import sys     app = qtgui.qapplication(sys.argv)     dialog = qtgui.qdialog()     ui = ui_dialog()     ui.setupui(dialog)     dialog.show()     sys.exit(app.exec_()) 

Comments

Popular posts from this blog

html5 - What is breaking my page when printing? -

c# - must be a non-abstract type with a public parameterless constructor in redis -

ajax - PHP/JSON Login script (Twitter style) not setting sessions -