【问题标题】:Underline a letter on a button in MaxscriptMaxscript中按钮上的字母下划线
【发布时间】:2021-11-14 02:23:51
【问题描述】:

我一直在寻找一种方法来执行此操作,例如在 queryBox 中,其中 Y 和 N 的 Yes 和 No 下划线表示如果您按下它们就会被按下。

这是我在 Button 之前放置 & 符号的代码和错误生成的屏幕截图。

try destroyDialog testRol catch()
rollout testRol "testRol" (
  button btn_test "&Button"
  )
createDialog testRol 100 45


编辑:

即使我尝试使用\x0332Yes,它也不起作用。确实如此,但下划线没有正确排列,并且在 B 之前使用时看起来很乱。

我使用了硬编码的下划线字母,这并不理想,所以如果有人知道一个很好的解决方案来避免这种情况。

这是一个尝试,因为它可以帮助您解决这个问题:

try destroyDialog testRol catch()
rollout testRol "testRol" (
  button btn_yes "Y̲es (Working)" width:120 across:4
  button btn_no "N̲o (Working)" width:120
  button btn_button_not_working "\x0332Button (Not Working)" width:120
  button btn_yes_not_working "\x0332Yes (Kinda Working)" width:120
  )
createDialog testRol 525 45

【问题讨论】:

    标签: maxscript


    【解决方案1】:

    取决于您的期望,您可以在转出控件中使用 .NET 按钮但您必须自己设置样式以匹配主题并使用系统样式使其看起来像 maxscript 按钮:

    try destroyDialog testRol catch()
    rollout testRol "MXS + .NET"
    (
        dotNetControl btnMakeCylinder "Button" text:"&Make Cylinder" width:120 height:25
        on btnMakeCylinder mouseClick evnt arg do with undo on Cylinder isSelected:on
        on testRol open do btnMakeCylinder.FlatStyle = btnMakeCylinder.FlatStyle.System
    )
    createDialog testRol
    

    或者您可以使用 MaxForm,其中按钮将继承颜色,但它仍然不会像 UI 的其余部分:

    (
        local form = dotNetObject "MaxCustomControls.MaxForm"
        form.Text = ".NET form"
    
        fn makeCylinder = with undo on Cylinder isSelected:on
    
        local btnMakeCylinder = dotNetObject "Button"
        btnMakeCylinder.Text = "&Make Cylinder"
        dotNet.addEventHandler btnMakeCylinder "MouseClick" makeCylinder
    
        form.Controls.Add btnMakecylinder
        form.ShowModeless()
    )
    

    或者您可以使用 Qt UI,它有自己的一系列缺点(例如必须始终显式指定撤消记录),而且它相当冗长:

    (
        local legacy = (python.import "sys").version_info[1] < 3
        local QtGui = python.import "PySide2.QtGui"
        local QtWidgets = python.import "PySide2.QtWidgets"
        local GetQMaxMainWindow = (if legacy then python.import "MaxPlus" else python.import "qtmax").GetQMaxMainWindow
    
        if isProperty ::testQtDialog #close do testQtDialog.close()
        testQtDialog = QtWidgets.QDialog(GetQMaxMainWindow())
        testQtDialog.setWindowTitle "Qt Window"
    
        local dialogLayout = QtWidgets.QVBoxLayout()
    
        fn makeCylinder = with undo on Cylinder isSelected:on
    
        local btnMakeCylinder = QtWidgets.QPushButton "&Make Cylinder"
        btnMakeCylinder.clicked.connect makeCylinder
        dialogLayout.addWidget btnMakeCylinder
    
        testQtDialog.setLayout dialogLayout
        testQtDialog.show()
    )
    

    从 2022 年开始,您还可以通过这种方式使用本机最大控件制作 Qt 窗口:

    if isKindOf testQtRol RolloutClass do UIAccessor.closeDialog testQtRol.hwnd
    rollout testQtRol "Qt Rollout"
    (
        QtButton btnMakeCylinder "&Make cylinder" row:0 column:2
        on btnMakeCylinder pressed do with undo on Cylinder isSelected:on
    )
    createQtDialog testQtRol
    

    【讨论】:

    • 感谢您的出色回答,尽管遗憾的是没有办法使用标准控件来做到这一点,这是一种耻辱。我将看看 .NET 按钮的样式是否可以与内置按钮匹配。你对我如何像Y̲es 那样硬编码 Y 有什么想法?编辑,当脚本被加密时,它会这样做,所以硬编码是不好的。 https://i.imgur.com/xZci87d.png
    • 如果您在 dotNet 按钮上使用 btn.FlatStyle = btn.FlatStyle.System,它将看起来与 Max 中的按钮一模一样。我从 DenisT here 得到这个。所以我最终选择了 .NET 按钮控件,效果很好。您可以将该样式添加到答案中,我会将其标记为已接受:) 谢谢@Swordslayer。
    • 很好,DenisT 是人 :) 已编辑。
    • 是的,我很惊讶它是如此晦涩和简单。我通过我的 maxscript sn-ps 和其他示例进行了搜索,唯一使用它的是 Kstudio 的 Show DotNet Properties 脚本。 PS。我不敢相信我教了你一些东西(至少传得很好!)
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2021-11-14
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2016-03-13
    相关资源
    最近更新 更多