how to change the position of a list of QRadioButton on a scrollArea?
Solved
General and Desktop
-
I create a list of elements in a scrollAreaWidget,the problem the sentences in the scrollArea are not on the same with the a top arrow of the scrollBar. I got the result like this:
the program of the scrollArea:ui->scrollArea->setWidget(ui->scrollAreaWidgetContents); for(int i=0;i<64;i++){ radio_name.clear(); radio_name.append("RadioButton_"); radio_name.append(QString::number(i+1)); radioButtons[i]=new QRadioButton(ui->scrollAreaWidgetContents); radioButtons[i]->setObjectName(QString::fromUtf8(radio_name.toStdString().c_str())); radioButtons[i]->setStyleSheet(QString::fromUtf8("QRadioButton{\n" "font-family: \"Helvetica Neue LT W1G\";\n" "font-size: 16px;\n" "}\n" "\n" "QRadioButton::indicator {\n" " width: 25px;\n" " height: 25px;\n" "}\n" "\n" " QRadioButton::indicator:checked\n" " {\n" " image: url(icons/check_cursor.png);\n" " }")); radioButtons[i]->setFocusPolicy(Qt::NoFocus); radioButtons[i]->setGeometry(QRect(10,(i+1)*25,400,30 )); radio_text.clear(); radio_text.append("Sentence "); radio_text.append(QString::number(i)); radioButtons[i]->setText(radio_text.toStdString().c_str()); label_name.clear(); label_name.append("Label_"); label_name.append(QString::number(i+1)); labels[i]=new QLabel(ui->scrollAreaWidgetContents); labels[i]->setObjectName(label_name.toStdString().c_str()); labels[i]->setGeometry(QRect(370,(i+1)*25,100,30)); label_text.clear(); label_text.append("AAA"); labels[i]->setText(label_text.toStdString().c_str()); } ui->scrollAreaWidgetContents->setGeometry(0,0,480,2405); the styleSheet of the scrollArea:
QFrame{ border:solid; } QScrollBar:vertical { width: 15px; margin:30px 0 30px 0; border-style: solid; } QScrollBar::handle:vertical { min-height: 30px; border: solid ; } QScrollBar::add-line:vertical { subcontrol-position: bottom; subcontrol-origin: margin; border: solid ; height: 30px; } QScrollBar::sub-line:vertical { subcontrol-position: up; subcontrol-origin: margin; border: solid ; height: 30px; } QScrollBar::add-page:vertical, QScrollBar::sub-page:vertical { background: none; } QScrollBar::up-arrow:vertical { image: url(image/up-arrow.png); } QScrollBar::down-arrow:vertical { image: url(image/down-arrow.png); }
how to fix that issue?
-
Hi and welcome
- the problem the sentences in the scrollArea are not on the same with the a top arrow of the scrollBar.
Im afraid i dont understand what is not working.
Also normally a layout is used with scrollArea and then its not possible to move any of the widgets.
If you didn't not use a layout, then
radioButtons[i]->move( X,Y); could be used.
-
ui->scrollArea->setWidget(ui->scrollAreaWidgetContents); for(int i=0;i<64;i++){ radio_name.clear(); radio_name.append("RadioButton_"); radio_name.append(QString::number(i+1)); radioButtons[i]=new QRadioButton(ui->scrollAreaWidgetContents); radioButtons[i]->setObjectName(QString::fromUtf8(radio_name.toStdString().c_str())); radioButtons[i]->setStyleSheet(QString::fromUtf8("QRadioButton{\n" "font-family: \"Helvetica Neue LT W1G\";\n" "font-size: 16px;\n" "}\n" "\n" "QRadioButton::indicator {\n" " width: 25px;\n" " height: 25px;\n" "}\n" "\n" " QRadioButton::indicator:checked\n" " {\n" " image: url(icons/check_cursor.png);\n" " }")); radioButtons[i]->setFocusPolicy(Qt::NoFocus); radioButtons[i]->setGeometry(QRect(10,i*25,400,30 )); radio_text.clear(); radio_text.append("Sentence "); radio_text.append(QString::number(i)); radioButtons[i]->setText(radio_text.toStdString().c_str()); label_name.clear(); label_name.append("Label_"); label_name.append(QString::number(i+1)); labels[i]=new QLabel(ui->scrollAreaWidgetContents); labels[i]->setObjectName(label_name.toStdString().c_str()); labels[i]->setGeometry(QRect(370,i*25,100,30)); label_text.clear(); label_text.append("AAA"); labels[i]->setText(label_text.toStdString().c_str()); } ui->scrollAreaWidgetContents->setGeometry(0,0,480,2405); the styleSheet of the scrollArea:
QFrame{ border:solid; } QScrollBar:vertical { width: 15px; margin:30px 0 30px 0; border-style: solid; } QScrollBar::handle:vertical { min-height: 30px; border: solid ; } QScrollBar::add-line:vertical { subcontrol-position: bottom; subcontrol-origin: margin; border: solid ; height: 30px; } QScrollBar::sub-line:vertical { subcontrol-position: up; subcontrol-origin: margin; border: solid ; height: 30px; } QScrollBar::add-page:vertical, QScrollBar::sub-page:vertical { background: none; } QScrollBar::up-arrow:vertical { image: url(image/up-arrow.png); } QScrollBar::down-arrow:vertical { image: url(image/down-arrow.png); }