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
Code:
{
//HexView widget2;
hexView.setGeometry(10,190,551,381);
}
int main(int argc, char *argv[])
{
MainWindow w;
w.setWindowTitle("Hex Inspector");
w.show();
hexTxt(w);
return a.exec();
}
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++
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
Re: Problem with QPlainTextEdit as a child QWidget in MainWindow
Code:
#include "mainwindow.h"
#include "ui_mainwindow.h"
#include <QGraphicsScene>
#include <QGraphicsView>
#include <QGraphicsItem>
#include <QPixmap>
#include <QPushButton>
#include <QWidget>
#include <QMap>
#include <QFile>
#include <QTextStream>
#include <QTimer>
#include <QRegExp>
#include <QPainter>
#include <QTextEdit>
//#include "highlighter.h"
MainWindow
::MainWindow(QWidget *parent
) : ui(new Ui::MainWindow)
{
ui->setupUi(this);
initTitle(); drawTitle();
initText();
}
///////////////////////////////////////////////////////////
MainWindow::~MainWindow()
{
delete ui;
}
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
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
Code:
ui->graphicsView_3->setSceneRect(0,0,691, 381);
dataScene.setSceneRect(0,0,691,381);
//QPen pen(Qt::black, 1);
//need to change color of text here:
/*
QFont console("Lucida Console", 10, QFont::Bold);
QGraphicsItem* item = dataScene.addText("A", console);
// "A" will be replaced with variable QString to
// draw out a table...
item->setPos(50,50);
*/
dataScene.addText("Hello World"); //temp test string
ui->graphicsView_3->setScene(& dataScene);
ui->graphicsView_3->show();