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 - How to add a button over a scrollArea (with absolute position)
Forum Updated to NodeBB v4.3 + New Features

QT - How to add a button over a scrollArea (with absolute position)

Scheduled Pinned Locked Moved Unsolved General and Desktop
2 Posts 2 Posters 443 Views 1 Watching
  • 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.
  • V Offline
    V Offline
    Vildnex
    wrote on last edited by Vildnex
    #1

    I have the following layout

    enter image description here

    What I'm trying to do here it's to place a custom widget (the BLUE one) over a scrollArea.

    Here it's how looks my outline:

    enter image description here

    And I would like to add that BLUE widget between home_page and scrollArea in terms of the outline, or other words in terms of GUI I would like to add that button over ScrollAreaContent BUT I don't want to move that button from its position at the moment when I'm moving the ScrollAreaContent.

    auto sizeX = 0.25 * w;
    auto sizeY = 0.9 * h;
    
    ui->scrollArea->setBaseSize(w,h);
    ui->scrollAreaWidgetContents->setBaseSize(w,h);
    
    ui->home_page->layout()->setMargin(0);
    ui->home_page->layout()->setContentsMargins(0,0,0,0);
    
    ui->scrollAreaWidgetContents->setLayout(new QHBoxLayout());
    ui->scrollAreaWidgetContents->layout()->setMargin(0);
    ui->scrollAreaWidgetContents->layout()->setContentsMargins(0,0,0,0);
    
    //This list is going to contain the buttons from scrollAreaWidgetContents
    auto buttons = new QList<MenuHomeButton *>();  
    
    //...
    //ADD buttons
    //...
    
    ui->stackedWidget->setCurrentIndex(0);
    
    
    for (auto button : *buttons) {
        ui->scrollAreaWidgetContents->layout()->addWidget(button);
        connect(button, SIGNAL(buttonClicked(int)), ui->stackedWidget, SLOT(setCurrentIndex(int)));
    }
    QScroller::grabGesture(ui->scrollArea, QScroller::LeftMouseButtonGesture);
    

    Does any of you have any idea how can I do this?

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

      Hi
      You mean so it just floats there on top ?
      alt text

      You simply make sure the parent you set on it, is not the scrollArea, but the widget that holds the scrollArea
      In your case i think mainwindow's centralWidget() would be fine.

      You do understand that having a floating widget like that might have side effects when
      you resize the window as it wont follow ScrollArea at all. So might end up in odd position if
      you resize main window a lot :)

      1 Reply Last reply
      1

      • Login

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