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. Qt Custom widget border problem
Forum Update on Monday, May 27th 2025

Qt Custom widget border problem

Scheduled Pinned Locked Moved Unsolved General and Desktop
5 Posts 2 Posters 1.7k 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.
  • A Offline
    A Offline
    Alatriste
    wrote on 20 Feb 2016, 11:39 last edited by
    #1

    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?

    1 Reply Last reply
    0
    • C Offline
      C Offline
      Chris Kawa
      Lifetime Qt Champion
      wrote on 20 Feb 2016, 13:23 last edited by Chris Kawa
      #2

      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);
      
      1 Reply Last reply
      0
      • A Offline
        A Offline
        Alatriste
        wrote on 20 Feb 2016, 13:55 last edited by Alatriste
        #3

        @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..

        1 Reply Last reply
        0
        • C Offline
          C Offline
          Chris Kawa
          Lifetime Qt Champion
          wrote on 20 Feb 2016, 14:20 last edited by Chris Kawa
          #4

          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 ;)

          1 Reply Last reply
          0
          • A Offline
            A Offline
            Alatriste
            wrote on 20 Feb 2016, 14:39 last edited by
            #5

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

            so generally it's works, thanks

            1 Reply Last reply
            0

            1/5

            20 Feb 2016, 11:39

            • Login

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