Unable to move ScrollBar to the top
-
Hi,
How are you moving this button ?
Do you have a widget set on the QScrollArea ? -
Wouldn't a QListWidget be simpler to use in your case ?
-
@SGaist Well, I've tried it but it doesn't work (I think).
The problem is that, when one of those buttons is clicked, It'll show a QLineEdit for password and a QPushButton to connect, like this:
Button in normal state:
Button clicked:
The problem is that these are not simple QPushButtons, but widgets of my own custom class that extends QFrame. So, when I put these same buttons in a QListWidget, this is what I get:
At first, every button is just a blue rectangle like seen in the first rows, but when clicked they extend onto the buttons below. So, the only button that works correctly is the last one. Is there a way to give more space to each button? And allow them to change size without breaking everything? -
Ok, I thought you were showing just a list of item but since it's a custom widget, the QScrollArea should be fine. Did you try to use QScrollArea::ensureWidgetVisible ?
-
AFAIK, it should not.
Can you reproduce that issue if you build a minimal application with a QScrollArea that you fill with plain QPushButton ?
-
@SGaist Nope, I did what you ask and it works perfectly. It doesn't make sense, the code is the almost the same. This is what I wrote:
QVBoxLayout* lay = qobject_cast<QVBoxLayout*>(ui->scrollAreaWidgetContents->layout()); for (int i = 0; i<20; i++) { QPushButton * button = new QPushButton(QString::number(i),this); button->setStyleSheet("QPushButton {color:white; background:blue}"); connect(button, &QPushButton::clicked, this, [this]() { QVBoxLayout* lay = qobject_cast<QVBoxLayout*>(ui->scrollAreaWidgetContents->layout()); QPushButton* button = qobject_cast<QPushButton*>(sender()); lay->removeWidget(button); lay->insertWidget(0,button); ui->scrollArea->verticalScrollBar()->setValue(0); }); lay->addWidget(button); }
-
@SGaist I changed the desing: Now QPushButtons are displayed in the QScrollArea, so the Button with the ssid and the other elements (The line to write a password, the button to connect to a network) are shown separately. With these simple changes, the code I wrote before works like a charm! True, It wasn't what I originally intended, but I realized that it's far better due to the circumstances where this app is going to be used.
Thanks for your time and your help!