Skip to content
  • 0 Votes
    2 Posts
    1k Views
    B

    I have found the answer!

    it is about the drawContents method of QTextDocument.
    There is a second parameter that you need to add in order to see the background image in your document.
    It's the a QRectF object that represend the size of the rect that the background image will be clipped into.

    void QTextDocument::drawContents(QPainter *p, const QRectF &rect = QRectF())
    Draws the content of the document with painter p, clipped to rect. If rect is a null rectangle (default) then the document is painted unclipped.

    So what I did is:

    easuresDoc.drawContents(&painter, pdfPrinter.paperRect()); // We print TextDocument of the Measures into the document pdfPrinter.newPage(); // We inject the current page and continue printing on new page averagesDoc.drawContents(&painter, pdfPrinter.paperRect()); // We print the TextDocument of the Averages into the document pdfPrinter.newPage(); // We inject the current page and continue printing on new page inOutDoc.drawContents(&painter, pdfPrinter.paperRect()); // We print the TextDocument of the Inputs/Outputs into the document

    pdfPrinter.paperRect is the rectangle of the page without the margin.

    Also if you want the background image to be printed scaled with no repeat than you need to put the printer into QPrinter::PrinterResolution

    QPrinter pdfPrinter(QPrinter::PrinterResolution);

  • 0 Votes
    7 Posts
    2k Views
    K

    syntax from documentation for border <width>px <border-style> <border-color>
    That's mean it should be px after border.

  • 0 Votes
    3 Posts
    491 Views
    K

    @jsulm, I apologize, I should've mentioned it in the original post: one of the requirements of the project is that we can not use any 3rd party library for the text editor, except for Qt.
    From what I see in the QScintilla github, it is ported to Qt on top of the TextEdit widget, so I will look further into their implementation to figure out how they've done it.

  • 0 Votes
    6 Posts
    939 Views
    T

    @artwaw Yes, it works fine eventually :)

  • 0 Votes
    1 Posts
    274 Views
    No one has replied
  • 0 Votes
    5 Posts
    2k Views
    jeanmilostJ

    @Chris-Kawa Thank you very much, this worked and was exactly what I needed to resolve my issue. Thank you also for the explanations, clear and precise.

  • 0 Votes
    5 Posts
    4k Views
    M

    @SGaist
    Good idea, I hadn't considered that approach.
    Thanks for the help!

  • 0 Votes
    1 Posts
    626 Views
    No one has replied
  • 0 Votes
    3 Posts
    1k Views
    R

    I have elucidated the dilemma regarding the doubt raised.

    First and foremost, I was confusing two concepts, TextEdit and TextDocument for the first contains the second, although they can be used interchangeably on any widget.

    On the other hand, I prefer QTextEdit, it has more features and is more versatile than QPlainTextEdit for creating a text editor and so investigated have equal performance in terms of resources used.

    I leave this reflection or as a solution in case someone is presented with any questions regarding this topic.

  • 0 Votes
    2 Posts
    784 Views
    raven-worxR

    @taek-seo said:

    how to convert 'QsciDocument' to 'QTextDocument*' ?
    or
    other way to find all word ?

    you don't since it doesn't subclass QTextDocument.

    Also i don't see any accessible methods in the QsciDocument class?!

  • 0 Votes
    1 Posts
    1k Views
    No one has replied
  • 0 Votes
    23 Posts
    10k Views
    T

    @kshegunov
    I understand, and respect your opinion on the matter but... I doesn't agree with most of them. Not wanting to make a big discussion of it, (mainly 'cause it's really out of the scope of the post) but...

    let's see:

    A singleton is not a real object, it's a facade for a global variable

    Well, yeah. I would say it's a (much) more elegant way to create a "global variable", since it ensures that only one will be created.

    A singleton created on the stack is initialized before main, so anything that actually depends on things done in main() as QObject does, may or may not work.

    Well, the way I learned to implement singleton on C++ uses heap.

    A singleton that's constructed on the heap often is simply left undeleted - a memory leak. C++ is not JAVA, it's the programmers job to clean the memory up.

    Well, I'm not seeing a problem here. I dont mind putting a few deletes at the end of my main, or even connecting some signals.

    A singleton that's created on first use in the heap requires special measures to be taken, so the construction is thread safe.

    Again, not seeing a problem here, just a need to take some caution when coding.

    A singleton created on the stack can't guarantee order of initialization (whence point 2 derives). If you have more than one the loader will initialize them depending on its mood!

    Again, I don't create them on stack.

    A singleton that's created on the heap can't guarantee order of initialization ever!

    Not really sure what you mean here.

    A singleton is a global shared public resource in your application that promotes coupling, it actually couples every one of the classes that decide to use it.

    Some times you need that coupling. You need to center the processing in one point in the code. That's what controllers are all about.

    A singleton is not thread-safe by design, and can't be reentrant as there is only one.

    Not really. For data classes, you're right. But for controllers, they can be thread safe as long as their attributes are read-only

    Why your worker object should not be a singleton

    My worker object is not a singleton. My controller object (the one that creates the worker objects) is.

    The fact that something is called a "design pattern" in some book, doesn't mean you should use it.

    But means that it have its uses.

  • Import from Odt

    Unsolved General and Desktop
    3
    0 Votes
    3 Posts
    2k Views
    P

    Odt import file is very easy...

    OOReader.h is my work, is a subset from Okular KDE ...
    https://github.com/pehohlva/fop-miniscribus/blob/master/OO_Widged/oasis/OOReader.h
    2017 the best way is now textutil from mac it convert doc rtf docx odt and many other format to txt or html to play in QTextedit ...

    void ZipDoc::handler_txtutils( const QString file ) { qDebug() << "### handler use-> " << __FUNCTION__; //// converter = /usr/bin/textutil if (converter.size() < 4) { text_s = QString("textutil -convert .. unable to read! or not mac osx."); } //// ram->LoadFile(file); //// const QByteArray base = ram->stream(); QTime myTimer; myTimer.start(); QProcess *process = new QProcess(NULL); process->setReadChannelMode(QProcess::MergedChannels); process->start(converter, QStringList() << "-convert" << "txt" << file << "-stdout", QIODevice::ReadOnly ); if (!process->waitForFinished()) { text_s = QString("Unable to read!."); } else { text_s = strip_tag(process->readAll()); } qDebug() << "### handler_txtutils time-> " << myTimer.elapsed(); }
  • 0 Votes
    2 Posts
    1k Views
    collycrkC

    @Aleksey_A
    I am as green to Qt as one can be, a newbie for sure.
    But here goes: Maybe changing the QPrinter printer(QPrinter::HighResolution) to
    QPrinter printer(QPrinter::ScreenResolution) would help.

  • 0 Votes
    4 Posts
    3k Views
    SGaistS

    You can find an example of this in the "Advanced Qt Programming: Creating Great Software with C++ and Qt 4" book code samples.

  • 0 Votes
    1 Posts
    820 Views
    No one has replied
  • 0 Votes
    1 Posts
    2k Views
    No one has replied
  • 0 Votes
    2 Posts
    1k Views
    Chris KawaC

    < and > are special characters in html. To display them literally you can use entities: &lt; and &gt; i.e. &lt;80 will result in <80.
    For a list of possible entities you can scout the web, e.g. here.

  • 0 Votes
    2 Posts
    2k Views
    SGaistS

    Hi and welcome to devnet,

    What about painting a partially transparent rectangle over the part of the text that should be highlighted ? You could draw the text first and then the rectangle over.

    Hope it helps