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 include .txt on Qt
Forum Updated to NodeBB v4.3 + New Features

How to include .txt on Qt

Scheduled Pinned Locked Moved Unsolved General and Desktop
196 Posts 11 Posters 135.9k Views 3 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.
  • P Payx
    1 Jan 2017, 14:06

    What is the simpliest method ? ahah

    M Offline
    M Offline
    mrjj
    Lifetime Qt Champion
    wrote on 1 Jan 2017, 14:09 last edited by
    #115

    @Payx said in How to include .txt on Qt:

    What is the simpliest method ? ahah

    I think to paint on image as you can then later just
    show in QLabel and might not even need to make a PaintEvent.
    This new image should be the size of the red rect one where u scan for colors.
    so you will draw the mini images on this new picmap and then its the final pixmap i assume.

    1 Reply Last reply
    0
    • P Offline
      P Offline
      Payx
      wrote on 1 Jan 2017, 14:17 last edited by
      #116

      so on my rectangle i create a label and i display the pixmap in the label ?

      M 1 Reply Last reply 1 Jan 2017, 14:22
      0
      • P Payx
        1 Jan 2017, 14:17

        so on my rectangle i create a label and i display the pixmap in the label ?

        M Offline
        M Offline
        mrjj
        Lifetime Qt Champion
        wrote on 1 Jan 2017, 14:22 last edited by
        #117

        @Payx
        I dont know what rectangle is.
        the QLabel should/could be placed on UI and after you created the final image and OUTSIDE
        of any loops
        you can do
        ui->Label->setPix thing.

        1 Reply Last reply
        0
        • P Offline
          P Offline
          Payx
          wrote on 1 Jan 2017, 14:46 last edited by
          #118

          so in this loop

            for(int x = topLeft.x(); x < maxX; ++x) {
              for(int y = topLeft.y(); y < maxY; ++y) {
          

          i can include

          QLabel *label = new QLabel(this);
                foreach( QRgb key, Costs.keys() ) {
                  QColor BaseColor( key );
                  if (Costs.contains( colour.rgb() ) || IsCloseColor(BaseColor, colour) )  {
                    CostInfo& ci = Costs[colour.rgb()];
          //          int Cost = ci.Cost;
                    QPixmap pix( ci.ImageName );
          					QPixmap scaledPix = pix.scaled(   8, 8,
          																				 Qt::KeepAspectRatio,
          																				 Qt::SmoothTransformation
          																				 );
          
          ui->label->setPixmap(pix);
          

          ?

          M 1 Reply Last reply 1 Jan 2017, 14:49
          0
          • P Payx
            1 Jan 2017, 14:46

            so in this loop

              for(int x = topLeft.x(); x < maxX; ++x) {
                for(int y = topLeft.y(); y < maxY; ++y) {
            

            i can include

            QLabel *label = new QLabel(this);
                  foreach( QRgb key, Costs.keys() ) {
                    QColor BaseColor( key );
                    if (Costs.contains( colour.rgb() ) || IsCloseColor(BaseColor, colour) )  {
                      CostInfo& ci = Costs[colour.rgb()];
            //          int Cost = ci.Cost;
                      QPixmap pix( ci.ImageName );
            					QPixmap scaledPix = pix.scaled(   8, 8,
            																				 Qt::KeepAspectRatio,
            																				 Qt::SmoothTransformation
            																				 );
            
            ui->label->setPixmap(pix);
            

            ?

            M Offline
            M Offline
            mrjj
            Lifetime Qt Champion
            wrote on 1 Jan 2017, 14:49 last edited by
            #119

            @Payx
            yes something like that.
            if pix is the FINISHED result. seems not.

            That code would just show the original one?

            and why new the qlabel? Why not just add to UI file with designer?

            1 Reply Last reply
            0
            • P Offline
              P Offline
              Payx
              wrote on 1 Jan 2017, 15:36 last edited by
              #120

              Because it will not return only one picture, if my picture is 540540 and my rectangle is 88 i cannot just add a label to display 70 picture.

              at the end it will have http://www.hostingpics.net/viewer.php?id=354728program.png

              by replacing all the rectangle by a picture, it depends the color of the rectangle

              1 Reply Last reply
              0
              • P Payx
                1 Jan 2017, 12:00

                @ambershark Lol

                I prefer learn instead of just don't understand what i'm doing, i know i'm very bad to programmation by now but maybe in few years i'il be like mrjj haha !

                for the QPoint, i use it here :

                void MainWindow::on_push2_clicked()
                {
                
                
                	for (int i=0;i<pixi.width();i+=z){
                						 for (int j=0;j<pixi.height();j+=z){
                							 k=k+0.06;
                							Remplissage(pixi,QPoint(i,j),QSize(z,z),Couleurdominante(pixi,QPoint(i,j),QSize(z,z)));
                
                		}
                	}
                
                

                but i use the QPixmap scaledPix .....
                in my function

                void Remplissage(QImage& image, const QPoint& topLeft, const QSize& rectangle, const QColor& colour) {
                

                so it tell that j and i was not declared in this scope

                so i declared i and j in my .h

                #ifndef MAINWINDOW_H
                #define MAINWINDOW_H
                
                #include <QMainWindow>
                #include <QPixmap>
                #include <QPoint>
                #include <QSize>
                #include <iostream>
                #include <QMapIterator>
                #include <QMap>
                
                namespace Ui {
                class MainWindow;
                }
                
                struct CostInfo {
                  QString ImageName;
                  int     Cost;
                };
                
                int j;
                int i;
                
                class MainWindow : public QMainWindow {
                  Q_OBJECT
                
                 public:
                  explicit MainWindow(QWidget* parent = 0);
                
                  ~MainWindow();
                
                 private slots:
                  void on_push_clicked();
                  void on_push2_clicked();
                  void on_verticalSlider_sliderMoved(int position);
                
                 private:
                  Ui::MainWindow* ui;
                  QImage pixi;
                  QPixmap pixa;
                  float k;
                  int a;
                
                
                  int z = 1;
                  int b;
                };
                
                #endif // MAINWINDOW_HH
                
                

                it will work?

                //

                it tell that painter was not declared too, so i search to the QPainter class,

                it's "void QPainter::drawPixmap(const QPoint & point, const QPixmap & pixmap)" that i should use ?

                A Offline
                A Offline
                ambershark
                wrote on 2 Jan 2017, 00:49 last edited by
                #121

                @Payx said in How to include .txt on Qt:

                @ambershark Lol

                I prefer learn instead of just don't understand what i'm doing, i know i'm very bad to programmation by now but maybe in few years i'il be like mrjj haha !

                Haha it's good that you are learning instead of asking for it done like a lot of people on these forums. And hey we all started out bad, don't worry you'll be good in no time if you stick with it. ;)

                I was just quite impressed with the number of posts in this topic.

                My L-GPL'd C++ Logger github.com/ambershark-mike/sharklog

                P 1 Reply Last reply 2 Jan 2017, 14:09
                0
                • A ambershark
                  2 Jan 2017, 00:49

                  @Payx said in How to include .txt on Qt:

                  @ambershark Lol

                  I prefer learn instead of just don't understand what i'm doing, i know i'm very bad to programmation by now but maybe in few years i'il be like mrjj haha !

                  Haha it's good that you are learning instead of asking for it done like a lot of people on these forums. And hey we all started out bad, don't worry you'll be good in no time if you stick with it. ;)

                  I was just quite impressed with the number of posts in this topic.

                  P Offline
                  P Offline
                  Payx
                  wrote on 2 Jan 2017, 14:09 last edited by
                  #122

                  @ambershark No problem ^^!

                  1 Reply Last reply
                  0
                  • P Offline
                    P Offline
                    Payx
                    wrote on 5 Jan 2017, 15:15 last edited by Payx 1 Jul 2017, 00:03
                    #123
                    This post is deleted!
                    1 Reply Last reply
                    0
                    • P Offline
                      P Offline
                      Payx
                      wrote on 7 Jan 2017, 00:04 last edited by
                      #124

                      I tried something without you (sorry ahah)

                      QLabel abc;
                      abc.setPixmap(scaledPix);
                      abc.show();
                      
                      

                      it compiles but there is a error : QPixmap::scaled: Pixmap is a null pixmap

                      M 1 Reply Last reply 7 Jan 2017, 01:32
                      0
                      • P Payx
                        7 Jan 2017, 00:04

                        I tried something without you (sorry ahah)

                        QLabel abc;
                        abc.setPixmap(scaledPix);
                        abc.show();
                        
                        

                        it compiles but there is a error : QPixmap::scaled: Pixmap is a null pixmap

                        M Offline
                        M Offline
                        mrjj
                        Lifetime Qt Champion
                        wrote on 7 Jan 2017, 01:32 last edited by mrjj 1 Jul 2017, 01:32
                        #125

                        @Payx said in How to include .txt on Qt:

                        scaledPix

                        Sounds like scaledPix is not initialize as it should , which often
                        comes from not being able to load a file.

                        Make sure the image you are scaling, is indeed valid. (loaded)

                        1 Reply Last reply
                        0
                        • P Offline
                          P Offline
                          Payx
                          wrote on 7 Jan 2017, 01:51 last edited by Payx 1 Jul 2017, 02:09
                          #126

                          Before posting, i've tried to just

                          QPixmap pix(":/img/ballebleue.png")
                          ui->setPixmap .....
                          

                          and it works

                          u said "scaledPix is not initialize as it should ?"

                          EDIT : Happy New Year !

                          M 1 Reply Last reply 7 Jan 2017, 09:04
                          0
                          • P Payx
                            7 Jan 2017, 01:51

                            Before posting, i've tried to just

                            QPixmap pix(":/img/ballebleue.png")
                            ui->setPixmap .....
                            

                            and it works

                            u said "scaledPix is not initialize as it should ?"

                            EDIT : Happy New Year !

                            M Offline
                            M Offline
                            mrjj
                            Lifetime Qt Champion
                            wrote on 7 Jan 2017, 09:04 last edited by
                            #127

                            @Payx

                            Yes That would make the pix valid.

                            To get the error " Pixmap is a null pixmap" for scaledPix means that
                            it was not valid. It was empty. so if it came from a scale function, it means
                            that the image u scaled to get scaledPix was empty.

                            Happy new Year :)

                            1 Reply Last reply
                            0
                            • P Offline
                              P Offline
                              Payx
                              wrote on 7 Jan 2017, 16:51 last edited by
                              #128
                              					QLabel abc;
                              //          int Cost = ci.Cost;
                              					QPixmap pix( ci.ImageName );
                              					QPixmap scaledPix = pix.scaled(   8, 8,
                              																				 Qt::KeepAspectRatio,
                              																				 Qt::SmoothTransformation
                              																				 );
                              					abc.setPixmap(scaledPix);
                              					abc.show();
                              
                              

                              i have this :

                              so the error come from "QPixmap pix" who is empty

                              so the line "QPixmap pix( ci.ImageName );" dont create a pixmap from my QMap ?

                              1 Reply Last reply
                              0
                              • M Offline
                                M Offline
                                mrjj
                                Lifetime Qt Champion
                                wrote on 7 Jan 2017, 17:02 last edited by
                                #129
                                • QPixmap pix( ci.ImageName );" dont create a pixmap from my QMap ?

                                That would be my guess yes.

                                You can check pix with isNull()

                                1 Reply Last reply
                                0
                                • P Offline
                                  P Offline
                                  Payx
                                  wrote on 7 Jan 2017, 17:56 last edited by
                                  #130

                                  So i add the if :

                                  					if (pix.isNull()){
                                  					QPixmap pix(":/img/ballebleue.png");
                                  					};
                                  
                                  

                                  Same error as before "QPixmap::scaled: Pixmap is a null pixmap"

                                  M 1 Reply Last reply 7 Jan 2017, 17:58
                                  0
                                  • P Payx
                                    7 Jan 2017, 17:56

                                    So i add the if :

                                    					if (pix.isNull()){
                                    					QPixmap pix(":/img/ballebleue.png");
                                    					};
                                    
                                    

                                    Same error as before "QPixmap::scaled: Pixmap is a null pixmap"

                                    M Offline
                                    M Offline
                                    mrjj
                                    Lifetime Qt Champion
                                    wrote on 7 Jan 2017, 17:58 last edited by
                                    #131

                                    @Payx said in How to include .txt on Qt:

                                    if (pix.isNull()){
                                    QPixmap pix(":/img/ballebleue.png");
                                    };

                                    Well that would not really change anything as you create a new local pix and its not related to the "pix" outside
                                    You should find out if its invalid and then why it is

                                    if (pix.isNull()){
                                    qDebug() << "yep its no good";
                                    return;
                                    };

                                    1 Reply Last reply
                                    0
                                    • P Offline
                                      P Offline
                                      Payx
                                      wrote on 7 Jan 2017, 18:06 last edited by
                                      #132

                                      okay so i have that.

                                      yep its no good
                                      yep its no good
                                      yep its no good
                                      yep its no good
                                      yep its no good
                                      yep its no good
                                      yep its no good
                                      yep its no good
                                      yep its no good
                                      yep its no good
                                      yep its no good
                                      yep its no good
                                      yep its no good
                                      yep its no good
                                      QImage::pixel: coordinate (144,540) out of range
                                      QImage::pixel: coordinate (145,540) out of range
                                      QImage::pixel: coordinate (146,540) out of range
                                      QImage::pixel: coordinate (147,540) out of range
                                      QImage::pixel: coordinate (148,540) out of range
                                      QImage::pixel: coordinate (149,540) out of range
                                      QImage::pixel: coordinate (150,540) out of range
                                      QImage::pixel: coordinate (151,540) out of range
                                      yep its no good
                                      yep its no good
                                      yep its no good
                                      yep its no good
                                      yep its no good
                                      yep its no good
                                      yep its no good
                                      yep its no good
                                      yep its no good
                                      yep its no good
                                      yep its no good
                                      yep its no good
                                      yep its no good
                                      QImage::pixel: coordinate (168,540) out of range
                                      QImage::pixel: coordinate (169,540) out of range
                                      QImage::pixel: coordinate (170,540) out of range
                                      QImage::pixel: coordinate (171,540) out of range
                                      QImage::pixel: coordinate (172,540) out of range
                                      QImage::pixel: coordinate (173,540) out of range
                                      QImage::pixel: coordinate (174,540) out of range
                                      QImage::pixel: coordinate (175,540) out of range
                                      QImage::pixel: coordinate (168,541) out of range
                                      QImage::pixel: coordinate (169,541) out of range
                                      QImage::pixel: coordinate (170,541) out of range
                                      QImage::pixel: coordinate (171,541) out of range
                                      QImage::pixel: coordinate (172,541) out of range
                                      QImage::pixel: coordinate (173,541) out of range
                                      QImage::pixel: coordinate (174,541) out of range
                                      QImage::pixel: coordinate (175,541) out of range
                                      QImage::pixel: coordinate (168,542) out of range
                                      QImage::pixel: coordinate (169,542) out of range
                                      QImage::pixel: coordinate (170,542) out of range
                                      QImage::pixel: coordinate (171,542) out of range
                                      QImage::pixel: coordinate (172,542) out of range
                                      QImage::pixel: coordinate (173,542) out of range
                                      QImage::pixel: coordinate (174,542) out of range
                                      
                                      

                                      that's mean that my pix is null right?

                                      M 1 Reply Last reply 7 Jan 2017, 18:07
                                      0
                                      • P Payx
                                        7 Jan 2017, 18:06

                                        okay so i have that.

                                        yep its no good
                                        yep its no good
                                        yep its no good
                                        yep its no good
                                        yep its no good
                                        yep its no good
                                        yep its no good
                                        yep its no good
                                        yep its no good
                                        yep its no good
                                        yep its no good
                                        yep its no good
                                        yep its no good
                                        yep its no good
                                        QImage::pixel: coordinate (144,540) out of range
                                        QImage::pixel: coordinate (145,540) out of range
                                        QImage::pixel: coordinate (146,540) out of range
                                        QImage::pixel: coordinate (147,540) out of range
                                        QImage::pixel: coordinate (148,540) out of range
                                        QImage::pixel: coordinate (149,540) out of range
                                        QImage::pixel: coordinate (150,540) out of range
                                        QImage::pixel: coordinate (151,540) out of range
                                        yep its no good
                                        yep its no good
                                        yep its no good
                                        yep its no good
                                        yep its no good
                                        yep its no good
                                        yep its no good
                                        yep its no good
                                        yep its no good
                                        yep its no good
                                        yep its no good
                                        yep its no good
                                        yep its no good
                                        QImage::pixel: coordinate (168,540) out of range
                                        QImage::pixel: coordinate (169,540) out of range
                                        QImage::pixel: coordinate (170,540) out of range
                                        QImage::pixel: coordinate (171,540) out of range
                                        QImage::pixel: coordinate (172,540) out of range
                                        QImage::pixel: coordinate (173,540) out of range
                                        QImage::pixel: coordinate (174,540) out of range
                                        QImage::pixel: coordinate (175,540) out of range
                                        QImage::pixel: coordinate (168,541) out of range
                                        QImage::pixel: coordinate (169,541) out of range
                                        QImage::pixel: coordinate (170,541) out of range
                                        QImage::pixel: coordinate (171,541) out of range
                                        QImage::pixel: coordinate (172,541) out of range
                                        QImage::pixel: coordinate (173,541) out of range
                                        QImage::pixel: coordinate (174,541) out of range
                                        QImage::pixel: coordinate (175,541) out of range
                                        QImage::pixel: coordinate (168,542) out of range
                                        QImage::pixel: coordinate (169,542) out of range
                                        QImage::pixel: coordinate (170,542) out of range
                                        QImage::pixel: coordinate (171,542) out of range
                                        QImage::pixel: coordinate (172,542) out of range
                                        QImage::pixel: coordinate (173,542) out of range
                                        QImage::pixel: coordinate (174,542) out of range
                                        
                                        

                                        that's mean that my pix is null right?

                                        M Offline
                                        M Offline
                                        mrjj
                                        Lifetime Qt Champion
                                        wrote on 7 Jan 2017, 18:07 last edited by
                                        #133

                                        @Payx
                                        Yes this means that the pictures in the table cannot be loaded.
                                        Are they in a resource ?

                                        1 Reply Last reply
                                        0
                                        • P Offline
                                          P Offline
                                          Payx
                                          wrote on 7 Jan 2017, 18:10 last edited by
                                          #134

                                          Yes i have that exactly :http://hpics.li/cc11b5c

                                          M 1 Reply Last reply 7 Jan 2017, 18:11
                                          0

                                          124/196

                                          7 Jan 2017, 00:04

                                          • Login

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