This should be possible, though I'm not sure you're going to like how much trouble it is or the final result. But in a nutshell...
Create the QPushButton
with your window as the parent (I'm assuming the QListWidget
is inside a window or some other container QWidget
which has the layout you mentioned). Whatever the parent widget is, that will be your frame of reference for the position coordinates of your button.
You will then need to position your button with QWidget::pos
. The trick is where and when.
Since the position is relative to the parent, you will need to get the parent's inner width and height with QWidget::size()
, subtract your button's width and height (QWidget::frameSize()
), and set the new position accordingly.
You will need to do this for each resize event of the parent widget. So, one way is to re-implement QWidget::resizeEvent()
in your parent window, and position the button from there.
This is not tested...
QPushButton* button = new QPushButton(this); // parent is current QWidget
button->show();
...
void MyWidget::resizeEvent(QResizeEvent *event) Q_DECL_OVERRIDE
{
QSize btnSize = button->frameSize();
QSize containerSize = this->size();
int newX = containerSize.width() - btnSize.width() - 10; // 10 is arbitrary margin
int newY = containerSize.height() - btnSize.height() - 10;
// position the button
button->move(newX, newY);
// call the superclass handler: substitute the actual superclass here
QWidget::resizeEvent(event);
}
You will most likely need to tweak things further, perhaps quite a bit, but that should be the general idea. The key is to reposition the button on each resize of the parent, which includes when it is initially shown.
HTH
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…