【问题标题】:How can I stop wxProgressDialog re-sizing?如何停止 wxProgressDialog 重新调整大小?
【发布时间】:2016-12-06 11:48:06
【问题描述】:

我在 Windows 上使用 wxProgressDialog。每当我更改对话框中的文本时,对话框都会重新调整大小以最好地适应文本,这会导致对话框经常重新调整大小,这看起来很糟糕。

我试过 SetMinSize 和 SetSizeHints 但这些似乎没有效果。 SetSize 似乎也不起作用。

(有关信息,对话框显示文件传输的进度。随着每个文件的传输,将显示其完整路径。这些差异很大,导致不断调整大小。)

我的代码基于示例中的以下代码:

static const int max = 100;

wxProgressDialog dialog("Progress dialog example",
                        // "Reserve" enough space for the multiline
                        // messages below, we'll change it anyhow
                        // immediately in the loop below
                        wxString(' ', 100) + "\n\n\n\n",
                        max,    // range
                        this,   // parent
                        wxPD_CAN_ABORT |
                        wxPD_CAN_SKIP |
                        wxPD_APP_MODAL |
                        //wxPD_AUTO_HIDE | // -- try this as well
                        wxPD_ELAPSED_TIME |
                        wxPD_ESTIMATED_TIME |
                        wxPD_REMAINING_TIME |
                        wxPD_SMOOTH // - makes indeterminate mode bar on WinXP very small
                        );

bool cont = true;
for ( int i = 0; i <= max; i++ )
{
    wxString msg;

    // test both modes of wxProgressDialog behaviour: start in
    // indeterminate mode but switch to the determinate one later
    const bool determinate = i > max/2;

    if ( i == max )
    {
        msg = "That's all, folks!\n"
              "\n"
              "Nothing to see here any more.";
    }
    else if ( !determinate )
    {
        msg = "Testing indeterminate mode\n"
              "\n"
              "This mode allows you to show to the user\n"
              "that something is going on even if you don't know\n"
              "when exactly will you finish.";
    }
    else if ( determinate )
    {
        msg = "Now in standard determinate mode\n"
              "\n"
              "This is the standard usage mode in which you\n"
              "update the dialog after performing each new step of work.\n"
              "It requires knowing the total number of steps in advance.";
    }

    // will be set to true if "Skip" button was pressed
    bool skip = false;
    if ( determinate )
    {
        cont = dialog.Update(i, msg, &skip);
    }
    else
    {
        cont = dialog.Pulse(msg, &skip);
    }

    // each skip will move progress about quarter forward
    if ( skip )
    {
        i += max/4;

        if ( i >= 100 )
            i = 99;
    }

    if ( !cont )
    {
        if ( wxMessageBox(wxT("Do you really want to cancel?"),
                          wxT("Progress dialog question"),  // caption
                          wxYES_NO | wxICON_QUESTION) == wxYES )
            break;

        cont = true;
        dialog.Resume();
    }

    wxMilliSleep(200);
}

if ( !cont )
{
    wxLogStatus(wxT("Progress dialog aborted!"));
}
else
{
    wxLogStatus(wxT("Countdown from %d finished"), max);
}

}

【问题讨论】:

  • 没有看到您的代码,我们的魔法玻璃球无法正常工作。你在哪里调用 Fit()?我希望只在 wxProgressDialog ctor。

标签: c++ windows wxwidgets


【解决方案1】:

选择文件路径显示的大小。如果路径较短,则添加空格,如果较长,则替换为省略号(...)

wxControl::Ellipsize 对此很有用(http://docs.wxwidgets.org/3.1/classwx_control.html#a0bb834cae2a8986aceddb89f84ef4ed1

【讨论】:

    【解决方案2】:

    如果你想要一个固定的大小,你需要使用wxGenericProgressDialog,似乎没有任何方法可以阻止在支持它的系统(Vista 和更高版本)下默认使用的本机对话框适应它的大小与其内容。

    【讨论】:

      猜你喜欢
      • 2011-04-14
      • 1970-01-01
      • 2014-11-29
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多