segunda-feira, 27 de janeiro de 2020

Qt Highlighter - Multiplos em vetor de inteiros

As duas versões anteriores deste programa,
que foram criadas uma no Qt e outra no C++ Builder,
era bastante limitada, o vetor de 100 elementos,
foi adaptado ao tamanho da janela e mesmo assim
foi muito bem aceito nos grupos onde postei.
Nesta versão preenchemos um vetor de inteiros
com 10000 elementos, e adaptamos um scrollArea
para um label, o que não é um procedimento padrão,
um QLabel não possui scrollArea,
mas fizemos isto funcionar com sucesso.





#include "mainwindow.h"
#include "ui_mainwindow.h"
#include <QVBoxLayout>
#include <QPainter>
#include <QLabel>

MainWindow::MainWindow ( QWidget *parent ) :
    QMainWindow ( parent ),
    ui ( new Ui::MainWindow )
{
    ui -> setupUi ( this );
    Contador ( );
}

MainWindow::~MainWindow ( )
{
    delete ui;
}
//====================================================================
QString str;
QString pesq;
int A [ 10000 ];
void MainWindow :: Contador ( ) {
    //Personaliza os componentes com css
    ui -> groupBox -> setStyleSheet("QGroupBox{"
                        "width:10;"
                        "height:10;"
                        "border-style: solid;"
                        "border-color: #f00 #0f0 #00f #fc0;"
                        "border-width: 15px;};");

    ui -> lineEdit -> setStyleSheet("QLineEdit{"
                                    "border: 2px solid blue;"
                                    "font-family: Arial;"
                                    "font-style: italic;"
                                    "font-size: 12pt;"
                                    "background: skyblue;"
                                    "color: black;"
                                    "font-weight: bold;};");

    ui -> pushButton -> setStyleSheet("QPushButton{"
                                      "font-weight: bold;"
                                      "font-size: 16px;"
                                      "font-family: Arial;"
                                      "font-style: italic;"
                                      "color: black;"
                                      "background-color: pink;"
                                      "border: 2px solid blue;};");

    ui -> pushButton_2 -> setStyleSheet("QPushButton{"
                                        "font-weight: bold;"
                                        "font-size: 16px;"
                                        "font-family: Arial;"
                                        "font-style: italic;"
                                        "color: black;"
                                        "background-color: pink;"
                                        "border: 2px solid blue;};");

    //Cria um label, Posiciona, e fixa um tamanho
    QLabel * l = new QLabel ( this );
    l -> setGeometry ( 40, 30, 600, 30 );
    l -> setStyleSheet("QLabel{"
                   "font-family: Arial;"
                   "font-style: italic;"
                   "font-weight: bold;"
                   "font-size: 16pt;"
                   "color : red;};");
    l -> setText("QT HIGHLIGHTER - MÚLTIPLOS EM VETOR DE INTEIROS");

    //Cria um label, Posiciona, e fixa um tamanho
    QLabel * l_2 = new QLabel ( this );
    l_2 -> setGeometry ( 270, 390, 220, 60 );
    l_2 -> setText ("<font face=\"Arial\">"
                    "<font size=\"5\">"
                    "<font color=\"blue\">"
                    "<i> <b> Por: </i></b>"
                    "<font color=\"red\">"
                    "<i> <b> Samuel Lima </i></b>"
                    "<br /> <font color=\"black\">"
                    "<i> <b> sa_sp10@hotmail.com </i></b>" );

    QVBoxLayout *layout = new QVBoxLayout ( );
    ui -> scrollAreaWidgetContents -> setLayout ( layout );
    ui -> scrollArea -> setGeometry ( QRect ( 50, 50, 560, 300 ) );
    ui -> scrollAreaWidgetContents -> setStyleSheet ("border: 3px solid blue;");

    //Posiciona, e fixa um tamanho para os componentes
    ui -> groupBox -> setGeometry ( 0, 0, 650, 447 );
    ui -> lineEdit -> setGeometry ( 50, 400, 100, 20 );
    ui -> pushButton -> setGeometry ( 170, 400, 40, 20 );
    ui -> pushButton_2 -> setGeometry ( 560, 400, 40, 20 );
    ui -> lineEdit -> setFocus ( );

    int a = 0, i;
    for( i = 0; i < 10000; i++ ) {
        A [ a ] =  i;
        a++;
    }
    int mult = 1000;
    for( a = 0; a < 10000; a++ ) {
            str += "    ";
        if ( a % 10 == 0 )
            str += "<p>";
        if ( a >= 0 && a < 10 && a % mult )
            str += ( "000" );
        if ( a == 0 )
            str += ( "000" );
        if ( a >= 10 && a < 100 )
            str += ( "00" );
        if ( a >= 100 && a < 1000 )
            str += ( "0" );
        str += QString::number (  A [ a ] );
    }

    //Fixa os limites máximos de um label
    ui -> label -> setFixedSize ( 520, 34030 );
    ui -> label -> setAlignment ( Qt::AlignLeft|Qt::AlignTop );
    ui -> label -> setStyleSheet("QLabel { color : black; }");
    ui -> label -> setText (  str  );

    layout -> addWidget ( ui -> label );
}
//============================================================
void MainWindow::on_pushButton_clicked ( ) {
//SINTIU FALTA DE ALGUNS CÓDIGOS
}
//============================================================
void MainWindow::on_pushButton_2_clicked ( ){
    close ( );
}
//====================================================================
 
 
 
 
#ifndef MAINWINDOW_H
#define MAINWINDOW_H


#include <QMainWindow>
#include <stdlib.h>
namespace Ui {
class MainWindow;
}


class MainWindow : public QMainWindow
{
    Q_OBJECT


public:
    explicit MainWindow(QWidget *parent = nullptr);
    ~MainWindow();


private slots:
void Contador ( );


void on_pushButton_clicked();


void on_pushButton_2_clicked();


private:
    Ui::MainWindow *ui;
    int cont = 0;
};


#endif // MAINWINDOW_H

 
 
 
#include "mainwindow.h"
#include <QApplication>


int main(int argc, char *argv[])
{
    QApplication a(argc, argv);
    MainWindow w;
    w.show();


    return a.exec();
} 

Nenhum comentário:

Postar um comentário

Observação: somente um membro deste blog pode postar um comentário.