qt窗口居中显示


   QDesktopWidget *desktop = QApplication::desktop();
    Q_ASSERT(desktop != nullptr);
    QPoint last_new_window_pos_;
    const QRect geometry = desktop->availableGeometry(QCursor::pos());
    if (windows_.isEmpty() || windows_.size() == 1) {
     
        const QPoint center = geometry.center();
        return QPoint(center.x() - saveWidth / 2, center.y() - saveHeight / 2);
    } else {
     
    	
        last_new_window_pos_.setX(last_new_window_pos_.x() + 30);
        last_new_window_pos_.setY(last_new_window_pos_.y() + 30);
        if ((last_new_window_pos_.x() + saveWidth >= geometry.width()) ||
                (last_new_window_pos_.y() + saveHeight >= geometry.height())) {
     
            last_new_window_pos_.setX(0);
            last_new_window_pos_.setY(0);
        }
        return last_new_window_pos_;
    }

你可能感兴趣的:(Qt,Create,qt)