How to get minimize/restore/close rectangle?

梦想与她 提交于 2020-01-07 03:03:39

问题


I want to draw some text in the end of menu bar like this

But when the child window is maximized in the MDI project it looks like this

I need to fix this output.
I want to check if the active child is maximized and if it is I want to get minimize/restore/close rectangle to get them total width.
How can I get active child window and how can I get it's rectangle of buttons?


回答1:


// in yourMainWindow.cpp

...

auto child = mdiArea->addSubWindow(yourWidget);
connect(child, &QMdiSubWindow::windowStateChanged, this, &yourMainWindow::yourSlot);

...

void yourMainWindow::yourSlot(Qt::WindowStates oldState, Qt::WindowStates newState)
{
    if (newState.testFlag(Qt::WindowMaximized)) {
        auto child = qobject_cast<QMdiSubWindow *>(sender());
        if (!child)
            return;

        QStyleOptionComplex opt;
        opt.initFrom(child);

        auto size = child->style()->sizeFromContents(QStyle::CT_MdiControls, &opt, QSize(100, 20));
        qDebug() << size;
    }
}


来源:https://stackoverflow.com/questions/34433958/how-to-get-minimize-restore-close-rectangle

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!