Skip to content
  • 0 Votes
    4 Posts
    43 Views
    JonBJ

    @Khamza
    First to answer your question. Your new code delays the update till after the text edit has been shown. In that sense it is similar to the QTimer approach. For unknown reason you are claiming the code does not work correctly until after the text edit has been shown.

    There are cases in Qt which this is necessary. In particular sizes of widgets are not calculated till they are actually shown, so code which requires to know a size is often delayed in one of the above two fashions.

    HOWEVER I was never convinced by your assertion "The function itself is called but neither text is inserted nor block format changed:". While I could believe that possibly an operation on textCursor() might require the text edit to be shown I never thought that insertPlainText() for sure would depend on that. It should be callable any time, including e.g. during construction.

    I have now had time to create a minimal repro. Here are the 3 files:

    #include "passwordshowarea.h" #include <QApplication> int main(int argc, char *argv[]) { QApplication a(argc, argv); PasswordShowArea w; w.show(); return a.exec(); } #ifndef PASSWORDSHOWAREA_H #define PASSWORDSHOWAREA_H #include <QTextEdit> class PasswordShowArea : public QTextEdit { Q_OBJECT public: PasswordShowArea(QWidget *parent = nullptr); private: void init(); void updateBlockFormat(); }; #endif // PASSWORDSHOWAREA_H #include <QAbstractTextDocumentLayout> #include <QTimer> #include "passwordshowarea.h" PasswordShowArea::PasswordShowArea(QWidget *parent) : QTextEdit(parent) { init(); //doesn't work updateBlockFormat(); // works - gpt4 suggest // QTimer::singleShot(0, this, &PasswordShowArea::updateBlockFormat); } void PasswordShowArea::init() { // QObject::connect(document()->documentLayout(), &QAbstractTextDocumentLayout::update, // this, &PasswordShowArea::updatePasswordShowArea); setTextColor(palette().color(QPalette::Text)); } void PasswordShowArea::updateBlockFormat() { insertPlainText("Some text"); QTextBlockFormat fmt = textCursor().blockFormat(); fmt.setTextIndent(20); fmt.setLineHeight(fontMetrics().height() * 2, QTextBlockFormat::LineDistanceHeight); fmt.setBackground(Qt::red); textCursor().mergeBlockFormat(fmt); }

    I have made couple of tiny tweaks where I did not have all of your code. I added fmt.setBackground(Qt::red); so that we had something to see. And here is what I get:

    Screenshot 2024-12-21 093554.png

    You can see that not only do I get the inserted text but I do also get the QTextBlockFormat changes. Identical if I change it to only call updateBlockFormat() on the delayed timer. Ubuntu 24.04, Qt 6.4.2.

    Sooo.... I suggest you try just this code.

  • 0 Votes
    3 Posts
    161 Views
    S

    @SGaist Thank you very much. Gonna have a read trough it. :D

  • 0 Votes
    16 Posts
    826 Views
    S

    @SGaist Thank you very much. One last questions before closing this thread:

    Does using setListWigetItem (QListWidget) make an difference in performance compared to just using the widgets inside a scrollarea or is the overhead the same?

    Have a nice day! :)

  • 0 Votes
    30 Posts
    2k Views
    S

    @SGaist I actually have some of them built already. Thats why i was asking what would be better/ if my approach with the database would be viable. :)
    Have a nice easter.

  • 0 Votes
    4 Posts
    569 Views
    Pl45m4P

    @StudentScripter

    This?

    WindowSplit.png

    It's called Split Window / Window Tile or something like that and is a Window Manager functionality (in your case, X on Windows 7/10).
    Because frameless Qt toplevel Widgets don't request a Window decoration, I think X does not recognize that you want to snap/split it anyway.
    This is probably not doable with Qt only and platform/Window Manager dependent, maybe you need some extension. Haven't found one though.

    Edit:
    If you are fine with not using the native functionality, you could try to implement something like that using your Qt widget... when enabled, calculate the requested area (1/2, 1/4...) of your screen size and geometry and resize + move your widget accordingly.

  • 0 Votes
    19 Posts
    1k Views
    JonBJ

    @StudentScripter Yes, you can do that. And it shows you how they implemented stuff.

  • 0 Votes
    7 Posts
    453 Views
    SGaistS

    @StudentScripter When you set an item in the model, the model becomes the owner of the item and thus controls its lifetime. If calling removeRows would leave the item(s) it contains intact, you would just have a memory leak by now.

  • 1 Votes
    12 Posts
    702 Views
    Chris KawaC

    @JonB said:

    Which I have always regraded as devil's spawn

    Agreed. I see blockSignals() as an advanced tool to be used with great care and only when you're very aware of all consequences in given case. Similar to sender(). Definitely not something to be applied on a "let's see if it helps" basis.

  • 0 Votes
    5 Posts
    878 Views
    SGaistS

    @rsmwall hi and welcome to devnet,

    Did you already check the projects I linked (agreed they are non trivial) ?

    Do you really intend to create a new DE or do you just need something more fancy than a single window application in which case the Qt Wayland module might be of interest.

  • 0 Votes
    4 Posts
    461 Views
    GilboonetG

    @TomZ Thank you, I follow the order you mentioned and it works fine.

    if (doSVG) { painter.setFont(fNum); painter.setPen(pNum); painter.save(); painter.translate(c.toPointF()+ b.toPointF() +tit->pos()); painter.rotate(radToDeg(ra)); painter.drawText(- ti->boundingRect().width()/2, -2, QString::number(n)); painter.restore(); }

    deplUI6a.png

  • 0 Votes
    5 Posts
    948 Views
    supergS

    @SGaist That seems to be the solution, haha! Thanks.

  • 1 Votes
    1 Posts
    325 Views
    No one has replied
  • 0 Votes
    6 Posts
    584 Views
    JonBJ

    @Turbotroop
    OK, so:

    Is the code pasted now currently what you have, exactly? What error do you currently have? Have you acted on the previous comments?

    For example: although it won't generate a compilation error, it does not make any sense to set up all these boxes or arrays in the main window destructor, does it? Why not in, say, the constructor instead?

  • 0 Votes
    7 Posts
    721 Views
    bibasmallB

    @Chris-Kawa thank you, it helped to set the margins!

  • 0 Votes
    17 Posts
    7k Views
    R

    @jsulm ou! thank you!
    you had helped me a lot!!

  • 0 Votes
    3 Posts
    511 Views
    SGaistS

    Hi and welcome to devnet,

    That's a bit too vast of a topic to have a simpler answer.

    What element of Cyber Security do you have in mind ?
    At what level ?
    Cyber Security starts from giving people access to certain hardware / applications to the boot process of your machines/devices, the kernel/OS they are running, the applications you are using on them, the libraries that composes these applications, the devices you plug in the machines, etc.

  • 0 Votes
    7 Posts
    4k Views
    JonBJ

    @SimonSchroeder
    QDir is only for directories, not for files. So it is not a (suitable) candidate for general "file paths".

  • 0 Votes
    4 Posts
    659 Views
    J.HilkJ

    @Zwenig die einfachste Methode ist der package manager.

    den findest du eigentlich vorinstalliert in der Menüleiste, einfach nach Creator oder QtCreator suchen und installieren.

    darüber bekommst du auch eine version von Qt (Bibliothek), sollte neuer als 5.11 sein, also sollte dein Programm damit auch kompilieren

  • 0 Votes
    2 Posts
    431 Views
    jsulmJ

    @ELIF Please post the actual compiler/linker error. it is somewhere above of what you posted.

  • 0 Votes
    7 Posts
    777 Views
    G

    when I rerun, I am told that QtWebView cannot contain more than one item, so I guess I cannot save a c++ class in QtWebView, going through the doc I found that the c++ classes I needed had already been extended to the quick module. So, I'm going to use the c++ classes in this module instead. Thank you very much for your help.