Results 1 to 5 of 5

Thread: Problem with QPlainTextEdit as a child QWidget in MainWindow

  1. #1
    Join Date
    Mar 2010
    Posts
    86
    Thanks
    11
    Thanked 7 Times in 4 Posts
    Qt products
    Qt4 Qt5
    Platforms
    MacOS X Unix/X11 Windows

    Default Problem with QPlainTextEdit as a child QWidget in MainWindow

    I can't for the life of me, figure out how to get a tutorial page's code to work as a child widget inside my MainWindow
    I have it working with the ui form and a QTextedit. But I need the QPainter ability in the text area, so I read here that the QPlainTextedit is what you use... only problem is that I can't get the header and cpp of this class to be a widget in my main...
    http://doc.trolltech.com/4.5/widgets-codeeditor.html this is the example I am using. I'm shooting for this class or something close to it as a widget... I don't know if I'm just not giving it a setGeometry call or something.... Do I have to initialize it in the main.cpp? This CodeEditor class is what I need sorta for a Hex View Inspector code I have going... I guess I'm just not wrapping my head around the stucture of the *parent Widget and child Widget and how you add them correctly....
    I named my class HexView (it is a PlainTextedit) and I'm using somthing damn close to the CodeEditor class. I tried to initalize an instance of it in a method class in MainWindow with the code of hexView = new HexView(QWidget *parent); but this isn't working.... and I tried

    Qt Code:
    1. void hexTxt(QWidget &hexView)
    2. {
    3. //HexView widget2;
    4. hexView.setGeometry(10,190,551,381);
    5.  
    6. }
    7. int main(int argc, char *argv[])
    8. {
    9. QApplication a(argc, argv);
    10. MainWindow w;
    11. w.setWindowTitle("Hex Inspector");
    12. w.show();
    13. hexTxt(w);
    14.  
    15. return a.exec();
    16. }
    To copy to clipboard, switch view to plain text mode 
    in the main.cpp and can't get it to establish the freaking widget.... any feed back would be greatly appreciated.....
    oh ya using latest Qt version with C++

  2. #2
    Join Date
    Feb 2007
    Location
    Karlsruhe, Germany
    Posts
    469
    Thanks
    17
    Thanked 90 Times in 88 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: Problem with QPlainTextEdit as a child QWidget in MainWindow

    Hi there!

    Could you show us all your code? Most importantly the constructor of your MainWindow.

    Did you miss, that w is an instance of MainWindow and not your HexView?

    Joh

  3. #3
    Join Date
    Mar 2010
    Posts
    86
    Thanks
    11
    Thanked 7 Times in 4 Posts
    Qt products
    Qt4 Qt5
    Platforms
    MacOS X Unix/X11 Windows

    Default Re: Problem with QPlainTextEdit as a child QWidget in MainWindow

    Qt Code:
    1. #include "mainwindow.h"
    2. #include "ui_mainwindow.h"
    3.  
    4. #include <QGraphicsScene>
    5. #include <QGraphicsView>
    6. #include <QGraphicsItem>
    7. #include <QPixmap>
    8. #include <QPushButton>
    9. #include <QWidget>
    10. #include <QMap>
    11. #include <QFile>
    12. #include <QTextStream>
    13. #include <QTimer>
    14. #include <QRegExp>
    15. #include <QPainter>
    16. #include <QTextEdit>
    17. //#include "highlighter.h"
    18.  
    19. MainWindow::MainWindow(QWidget *parent) :
    20. QMainWindow(parent),
    21. ui(new Ui::MainWindow)
    22. {
    23. ui->setupUi(this);
    24. initTitle(); drawTitle();
    25.  
    26. initText();
    27. }
    28. ///////////////////////////////////////////////////////////
    29. MainWindow::~MainWindow()
    30. {
    31. delete ui;
    32.  
    33. }
    To copy to clipboard, switch view to plain text mode 

  4. #4
    Join Date
    Feb 2007
    Location
    Karlsruhe, Germany
    Posts
    469
    Thanks
    17
    Thanked 90 Times in 88 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: Problem with QPlainTextEdit as a child QWidget in MainWindow

    Can't help you like that. The only thing I can see is that you didn't show me any code, where you actually created an instance of your HexView class.

    I would suggest to create it in the MainWindow constructor. And add it into to some layout, that you set to the mainwindow.

    Johannes

  5. #5
    Join Date
    Mar 2010
    Posts
    86
    Thanks
    11
    Thanked 7 Times in 4 Posts
    Qt products
    Qt4 Qt5
    Platforms
    MacOS X Unix/X11 Windows

    Default Re: Problem with QPlainTextEdit as a child QWidget in MainWindow

    well now I took a big turn and decided to go with adding the Text into a QGraphicsView scene.
    This works out better so that I can use hovering and such, but how the heck do you change the text color and background text color for a one character graphicsItem? I tried in the stylesheet in the QGraphicsView in the ui, and have goofed with QBrush, and QPen. but they don't seem to be supported in QGraphicsScene.??¿¿?? The QFont is not helpful at all either....

    here's what I have for the drawing of the text to the scene.... going to use a QList<QStringList> as QGraphicsItem item, and then item->setPos(x,y) to put everything where I want, but I need to be able to change the font color...

    I kinda don't want to use a tableWidget, just the GraphicsView/Scene

    Qt Code:
    1. ui->graphicsView_3->setSceneRect(0,0,691, 381);
    2. dataScene.setSceneRect(0,0,691,381);
    3.  
    4. //QPen pen(Qt::black, 1);
    5.  
    6. //need to change color of text here:
    7.  
    8.  
    9. /*
    10.   QFont console("Lucida Console", 10, QFont::Bold);
    11.   QGraphicsItem* item = dataScene.addText("A", console);
    12.   // "A" will be replaced with variable QString to
    13.   // draw out a table...
    14.   item->setPos(50,50);
    15. */
    16.  
    17. dataScene.addText("Hello World"); //temp test string
    18.  
    19. ui->graphicsView_3->setScene(& dataScene);
    20. ui->graphicsView_3->show();
    To copy to clipboard, switch view to plain text mode 
    Last edited by budda; 17th April 2010 at 03:54.

Similar Threads

  1. Replies: 2
    Last Post: 19th November 2008, 10:01
  2. Child Widgets In MainWindow
    By RY in forum Newbie
    Replies: 3
    Last Post: 4th October 2008, 09:39
  3. Closing all of the mainWindow's child dialogs
    By JPNaude in forum Qt Programming
    Replies: 4
    Last Post: 2nd October 2008, 14:18
  4. MainWindow in front of child modeless dialog
    By jiveaxe in forum Qt Programming
    Replies: 4
    Last Post: 10th August 2007, 17:18
  5. Replies: 10
    Last Post: 17th August 2006, 16:12

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Digia, Qt and their respective logos are trademarks of Digia Plc in Finland and/or other countries worldwide.