Qt Custom widget border problem



  • I'm creating Qt widget custom border.
    I created widget and added QGridLayout on whole widget's area.

    Then I added four diagonal resize widgets for four corners, two horizontal resize widget bar and two vertical resize bar.
    And then Title bar widget with (minimize, maximize and close buttons)

    This is picture

    Image 1 link

    but after adding menu bar I'v got this. i.e Menu bar is not under title bar.

    image 2 link

    this is the code :

      setWindowFlags(Qt::FramelessWindowHint);
    
      ui.lfGridLayout_->setHorizontalSpacing(0);
      ui.lfGridLayout_->setVerticalSpacing(0);
      // Top Side
      ui.lfGridLayout_->addWidget(&dgResizebars[0], 0, 0, Qt::AlignLeft|Qt::AlignTop);
      ui.lfGridLayout_->addWidget(&hResizeBars_[0], 0, 1, Qt::AlignTop);
      ui.lfGridLayout_->addWidget(&dgResizebars[1], 3, 2, Qt::AlignLeft|Qt::AlignBottom);
      // Left side
      ui.lfGridLayout_->addWidget(&vResizeBars_[0], 1, 0, Qt::AlignLeft);
      ui.lfGridLayout_->addWidget(&dgResizebars[2], 3, 0, Qt::AlignRight|Qt::AlignBottom);
    
      // Bottom side
      ui.lfGridLayout_->addWidget(&hResizeBars_[1], 3, 1, Qt::AlignBottom);
      ui.lfGridLayout_->addWidget(&dgResizebars[3], 0, 2, Qt::AlignRight|Qt::AlignTop);
    
      //Right Side
      ui.lfGridLayout_->addWidget(&vResizeBars_[1], 1, 2,Qt::AlignRight);
    
    
      ui.lfGridLayout_->addWidget(&windowTitleBar_, 1, 1, Qt::AlignTop);
    
      ui.lfGridLayout_->addWidget(&menuBar_,        2, 1, Qt::AlignTop);
    

    how can I solve this?


  • Moderators

    Your numbering is confusing. You have a comment "Top Side" and you add something to row 3. You also add 3 things to the top and only 2 to the botton etc. Also you don't need the alignment flag. It is only needed when you have a fixed sized widget that is smaller than the grid cell it's gonna be in. In your case you want the widgets to fill entire cells, which is the default.

    Anyway, should be something like this:

    setWindowFlags(Qt::FramelessWindowHint);
    ui.lfGridLayout_->setContentsMargins(0, 0, 0, 0);
    ui.lfGridLayout_->setSpacing(0);
    
    //top (row 0)
    ui.lfGridLayout_->addWidget(&dgResizebars[0], 0, 0);
    ui.lfGridLayout_->addWidget(&hResizebars[0],  0, 1);
    ui.lfGridLayout_->addWidget(&dgResizebars[1], 0, 2);
    
    //bottom (row 4)
    ui.lfGridLayout_->addWidget(&dgResizebars[2], 4, 0);
    ui.lfGridLayout_->addWidget(&hResizebars[1],  4, 1);
    ui.lfGridLayout_->addWidget(&dgResizebars[3], 4, 2);
    
    //left side (rows 1-3)
    ui.lfGridLayout_->addWidget(&vResizebars[0], 1, 0, 3, 1); //spans 3 rows
    
    //right side (rows 1-3)
    ui.lfGridLayout_->addWidget(&vResizebars[1], 1, 2, 3, 1); //spans 3 rows
    
    //title bar (row 1)
    ui.lfGridLayout_->addWidget(&windowTitleBar_, 1, 1);
    
    //menu bar (row 2)
    ui.lfGridLayout_->addWidget(&menuBar_, 2, 1);
    
    //content (row 3)
    ui.lfGridLayout_->addWidget(&contentWidget, 3, 1);
    


  • @Chris-Kawa said:

    setContentsMargins

    I have one question about this: 4 th column parameter.

    ui.lfGridLayout_->addWidget(&vResizeBars_[0], 1, 0, 3, 1); //spans 3 rows
    
    

    this means that vResizebar srarts from first column and will take width until second column right?
    I replaced 4 th parameter from 1 to 0 like that

    ui.lfGridLayout_->addWidget(&vResizeBars_[0], 1, 0, 3, 0); //spans 3 rows
    

    and I have same result..


  • Moderators

    this means that vResizebar srarts from first column and will take width until second column right?

    No , that's not correct.

    ui.lfGridLayout_->addWidget(&vResizeBars_[0], 1, 0, 3, 1);
    

    Breaking down the params:
    1 - widget is placed in row 1
    0 - widget is placed in column 0
    3 - widget occupies 3 rows
    1 - widget occupies 1 column
    Don't put 0 in any of the last two parameters.

    Here's a picture to make it more clear:
    grid

    Edit: Ok, I think I know where the confusion came from. you probably meant "h" in "hResizebars" to mean "horizontally resizes window", while I meant "the bar itself is horizontal". If that's the case just mentally switch "h" and "v" in my picture and code ;)



  • "you probably meant "h" in "hResizebars" to mean "horizontally resizes window" - Right,

    so generally it's works, thanks


Log in to reply
 

Looks like your connection to Qt Forum was lost, please wait while we try to reconnect.