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. Multiple file edition
Forum Updated to NodeBB v4.3 + New Features

Multiple file edition

Scheduled Pinned Locked Moved General and Desktop
7 Posts 4 Posters 3.0k Views 1 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.
  • F Offline
    F Offline
    Forgive
    wrote on last edited by
    #1

    Well i'm trying to create a QTreeWidget with QTreeWidgetItem to store the files. Whenever someone clicks one of the items it opens the file in that specified item, read it's data and add a new tab and QPlainTextEdit to my QTabWidget and making that tab for THAT FILE ONLY. (Means that it stores the saved / un-saved contents of the file) How would i do that?

    Then since we have multiple tabs to switch files, how would i assign each file to that tab? I meant, when someone changes tab it shows the text of the file assigned to that tab.

    If you need better explain, tell me.

    1 Reply Last reply
    0
    • L Offline
      L Offline
      lgeyer
      wrote on last edited by
      #2

      Well, what exactly is your problem?

      Populate a QPlainTextEdit in the slot handling the QTreeWidget clicked signal and add it to the QTabWidget using QTabWidget::addTab(). Set the filename either as the tab label or as a dynamic property of the QPlainTextEdit so you can find out if a file is already opened by iterating over all opened files. Alternatively you can use an external mechanism of bookkeeping, like QHash<QString, QWidget*>, which keeps track of all opened files and the corresponding QPlainTextEdit widget, so you can easily switch to a specific file using QTabWidget::setCurrentWidget(), for example tabWidget->setCurrentWidget(openFilesHash.value(desiredFileName)).

      1 Reply Last reply
      0
      • F Offline
        F Offline
        Forgive
        wrote on last edited by
        #3

        QTabWidget doesn't have anything that let's us check if we're trying to change Tab.

        1 Reply Last reply
        0
        • F Offline
          F Offline
          fluca1978
          wrote on last edited by
          #4

          [quote author="Forgive" date="1325168995"]QTabWidget doesn't have anything that let's us check if we're trying to change Tab.[/quote]

          It has a "signal":http://developer.qt.nokia.com/doc/qt-4.8/qtabwidget.html#currentChanged that informs that we changed the tab.

          1 Reply Last reply
          0
          • F Offline
            F Offline
            Forgive
            wrote on last edited by
            #5

            I see. Also there's anyway to make the user able to left-click the Tab and show options?

            1 Reply Last reply
            0
            • F Offline
              F Offline
              fluca1978
              wrote on last edited by
              #6

              [quote author="Forgive" date="1325205672"]I see. Also there's anyway to make the user able to left-click the Tab and show options? [/quote]

              Which options are you talking about? You need to display a popup menu? I think the only way is to use an event handler that will catch the clicked event. Never done by myself.

              1 Reply Last reply
              0
              • A Offline
                A Offline
                andre
                wrote on last edited by
                #7

                Yes, sure that is possible. You can do such things, but you will need to handle the events yourself. Because you are using a QTabWidget, and that widget embeds QTabBar, subclassing isn't going to get you the events you need. You will need to use eventfilters. You can get a pointer to the embedded QTabBar using QObject::findChild<QTabBar*>. Then, you can install an event filter on it, and use any click the way you want it.

                I have used this technique to add features to QTabBar and QTabWidget that allow renaming tabs by double clicking them, and to make it possible to prevent the switch of a tab (to allow validation).

                1 Reply Last reply
                0

                • Login

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