Last active
August 27, 2019 01:15
-
-
Save jniemann66/7e9f383be7357c41beccb5e756034acd to your computer and use it in GitHub Desktop.
Qt align tops of widgets in separate layouts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// in Widget A, residing in some other layout, but part of the same window as widget B | |
// someBox is a widget somewhere in widgetA | |
void WidgetA::resizeEvent(QResizeEvent *event) | |
{ | |
widgetB->setBoxYPos(someBox->mapTo(this->window(), someBox->rect().topLeft()).y()); | |
QWidget::resizeEvent(event); | |
} | |
// in widget B, which has a member QVBoxLayout* mainLayout | |
// someWidget is a widget somewhere in Widget B's mainLayout | |
void WidgetB::setBoxYPos(int y) | |
{ | |
mainLayout->setSpacing(mainLayout->spacing() + y - someWidget->mapTo(this->window(), someWidget->rect().topLeft()).y()); | |
} | |
// note: use rect().topLeft() instead of pos() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment