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. how to change the position of a list of QRadioButton on a scrollArea?

how to change the position of a list of QRadioButton on a scrollArea?

Scheduled Pinned Locked Moved Solved General and Desktop
3 Posts 2 Posters 908 Views 2 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.
  • slimhsS Offline
    slimhsS Offline
    slimhs
    wrote on last edited by
    #1

    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:
    0_1473432016721_scroll.png
    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?

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

      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.

      1 Reply Last reply
      0
      • slimhsS Offline
        slimhsS Offline
        slimhs
        wrote on last edited by
        #3
         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);
        }
        
        1 Reply Last reply
        0

        • Login

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