Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. QWidget over and outside parent QMainwindow

QWidget over and outside parent QMainwindow

Scheduled Pinned Locked Moved Unsolved General and Desktop
4 Posts 4 Posters 5.6k Views
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • J Offline
    J Offline
    jacobP
    wrote on last edited by
    #1

    I have a mainWindow and a widget that will be a child of that main window. Below is a code example created with QTCreator.

    #include "mainwindow.h"
    #include "ui_mainwindow.h"
    
    MainWindow::MainWindow(QWidget *parent) :
        QMainWindow(parent),
        ui(new Ui::MainWindow)
    {
        ui->setupUi(this);
    
        //create test widget
            QWidget* blue_widget = new QWidget(); //no parent
            blue_widget->setFixedSize(100,100);
            blue_widget->setStyleSheet("background-color:blue;");
            blue_widget->setWindowFlags(Qt::FramelessWindowHint | Qt::Tool );
            blue_widget->setVisible(true);
            //create test widget END
    
            blue_widget->setParent(this);
            blue_widget->move(-50,-10);
    
            show();
    }
    
    MainWindow::~MainWindow()
    {
        delete ui;
    }
    

    Right now I can only see the part of the blue_widget that is inside the boundaries of the main window. I would like to be able to have the totality of the blue_widget shown. How can I prevent the main window cutting the blue_widget like that ? I really need to have the blue_widget to be a child of the main window.

    Thanks for the help.

    1 Reply Last reply
    0
    • SGaistS Offline
      SGaistS Offline
      SGaist
      Lifetime Qt Champion
      wrote on last edited by
      #2

      Hi,

      Why not set it as central widget ? Or put it in a QDockWidget ?

      Interested in AI ? www.idiap.ch
      Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

      1 Reply Last reply
      0
      • JeroentjehomeJ Offline
        JeroentjehomeJ Offline
        Jeroentjehome
        wrote on last edited by
        #3

        Hi,
        You should set the blue_widget as the central widget of the MainWindow, or fill the MainWindow with a QWidget in designer and set your blueWidget to that one. In designer you should set MainWindow to be e.g. a GridLayout, or any other layout. Leaving the MAinWindow without a layout will not force you Blue Widget to resize according the MainWindow size.

        Greetz, Jeroen

        1 Reply Last reply
        0
        • mrjjM Offline
          mrjjM Offline
          mrjj
          Lifetime Qt Champion
          wrote on last edited by
          #4

          Hi
          As long as the widget is a child of the mainwindow, it will be clipped to it.
          To have a floating window that is not clipped to parent, you can use QDialogs or
          simply do not set the parent. ( you must manually delete it then)

          Its by design that widgets are clipped. So you must make it a true window type ( as Dialog is) ( or using Qt::Window flag)
          or dont give it parent.

          http://doc.qt.io/qt-5/application-windows.html

          1 Reply Last reply
          3

          • Login

          • Login or register to search.
          • First post
            Last post
          0
          • Categories
          • Recent
          • Tags
          • Popular
          • Users
          • Groups
          • Search
          • Get Qt Extensions
          • Unsolved